静态变量编译之后,被编译器放到了可执行文件的哪个字段? 以下实验在ubuntu10.04上完成,使用gcc4.4.3。
测试源码如下:
- #include <stdio.h>
-
- int g_val_init = 45;
- int g_val_uninit;
- static int s_global_inited = 12;
- static int s_global_uninited;
-
- struct ct_type{
- char st_s_val;
- char st_val;
- };
-
- int
- foo()
- {
- static int s_foo_init = 67;
- static int s_foo_uninited;
-
- printf("hello..\n");
- return 0;
- }
-
- int main()
- {
- static int s_local_inited = 23;
- static int s_local_uninited;
- static struct ct_type s_ct = {.st_s_val=133, .st_val=132 };
- struct ct_type local_ct;
- int tmp = 100;
-
- printf("%d..\n", tmp);
- return 0;
- }
使用gcc -S static_val.c 编译:
|