When do I assign values to static variables in C language?

Source: Internet
Author: User

When do I assign values to static variables in C language?

The answer should be a value assignment during compilation.

Verification process:

Write a C language program as follows:

# Include "stdio. h"

Int main (){
Static int I;
Static int j = 0x12345678;

Printf ("% 02X", ih [t]);
Return 0;
}

Compile with Gcc to generate the target file: gcc-c test_static.c-o test_static.o

The location of the static variable is the same as that of the global variable. If it is an initialized static variable, it is stored in the. data Segment. If it is not initialized, it is stored in the. bss segment.

Use objdump to view the generated target file.

Objdump-t test_static.o


You can see the symbols and segments in the target file. <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + signature + 0mxposjnz8kjuw.vcd4kpha + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20150108/20150108093145374.jpg" alt = "">


Appendix: Commonly Used objdump commands:

Objdump-t obj file name: symbol table of the output target file
Objdump-h obj file name: summary of all the sections in the output target file
Objdump-j. text/. data-S obj file name: output the information of the specified segment


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.