分享

静态变量、全局变量在ELF文件中的位置

 astrotycoon 2013-08-17

   静态变量编译之后,被编译器放到了可执行文件的哪个字段? 以下实验在ubuntu10.04上完成,使用gcc4.4.3。

测试源码如下:

  1. #include <stdio.h>  
  2.   
  3. int g_val_init = 45;  
  4. int g_val_uninit;  
  5. static int s_global_inited = 12;  
  6. static int s_global_uninited;  
  7.   
  8. struct ct_type{  
  9.     char st_s_val;  
  10.     char st_val;  
  11. };  
  12.   
  13. int   
  14. foo()  
  15. {  
  16.     static int s_foo_init = 67;  
  17.     static int s_foo_uninited;  
  18.   
  19.     printf("hello..\n");  
  20.     return 0;  
  21. }  
  22.   
  23. int main()  
  24. {  
  25.     static int s_local_inited = 23;  
  26.     static int s_local_uninited;  
  27.     static struct ct_type s_ct = {.st_s_val=133, .st_val=132 };  
  28.     struct ct_type local_ct;  
  29.     int tmp = 100;  
  30.   
  31.     printf("%d..\n", tmp);    
  32.     return 0;  
  33. }  


使用gcc -S static_val.c 编译:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多