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