C语言中关于段的理解

一、
#include <stdio.h>
int main(void)
{
printf("hello-world!\n");
return 0;
}
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 7139 2013-10-12 06:29 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename
    916    264      8   1188    4a4 a.out


二、
#include <stdio.h>
int null[1000];
int main(void)
{
printf("hello-world!\n");
return 0;
}
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 7160 2013-10-12 06:25 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename
    916    264   4032   5212   145c a.out
三、
#include <stdio.h>
int null[1000]={0};
int main(void)
{
printf("hello-world!\n");
return 0;
}
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 7160 2013-10-12 06:35 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename
    916    264   4032   5212   145c a.out
四、
#include <stdio.h>
int null[1000]={1};
int main(void)
{
printf("hello-world!\n");
return 0;
}
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 11204 2013-10-12 06:28 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename
    916   4288      8   5212   145c a.out


五、
#include <stdio.h>
int null[1000]={1};
int main(void)
{
int local[1000];
printf("hello-world!\n");
return 0;
}
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 11204 2013-10-12 06:37 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename
    932   4288      8   5228   146c a.out
六、
#include <stdio.h>
int null[1000]={1};
int main(void)
{
int local[1000] = {1};
printf("hello-world!\n");
return 0;
}
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 11204 2013-10-12 06:40 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename

    964   4288      8   5260   148c a.out

七、

#include <stdio.h>
int null[1000]={1};
int main(void)
{
int local[1000] = {1};
printf("hello-world!\n");
return 0;
}

root@ubuntu:/home/albert# gcc -g  hello.c 
root@ubuntu:/home/albert# ls -al a.out 
-rwxr-xr-x 1 root root 12444 2013-10-12 06:51 a.out
root@ubuntu:/home/albert# size a.out 
   text   data    bss    dec    hex filename
    964   4288      8   5260   148c a.out

解析:(1)由一、二例子 和 三例子比较知道:BSS段不保存在目标文件中,除了记录BSS段在运行时所需要的大小。注意:当全局变量初始化为0时,也认为是未初始化,故放在BSS段;  (2) 由四五六可知,数据段保存在目标文件中;(3)文本段是最容易受优化措施影响的段,注意:a.out文件的大小受调试状态下编译的影响,但是段的大小不受影响。

    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值