C语言中关于段的理解

来源:互联网 发布:淘宝化妆品照片怎么拍 编辑:程序博客网 时间:2024/06/05 04:52
一、
#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文件的大小受调试状态下编译的影响,但是段的大小不受影响。

    

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 我感昌一直不好怎么办 腰间盘突出晚上睡觉痛怎么办 天天吃撑了怎么办啊 一吸气就想咳嗽怎么办 鼻子堵住了怎么办没法吸气时 一只鼻子不通气怎么办 练瑜伽后特别饿怎么办 站一天小腿肿了怎么办 练腹肌腰粗了怎么办 大专不交学费.然后退学怎么办 练瑜伽压腿一字马受伤了怎么办 银行工作人员借钱不还怎么办 借钱不还跑了但有工作怎么办 亲戚家借钱不还怎么办 学习瑜伽教练口令好复杂怎么办 练瑜伽腿的柔韧性不够怎么办 瑜伽扭转时手抓不到脚怎么办 练瑜伽腿部太硬怎么办 褶皱衣服不紧了怎么办 吃撑了肚子涨怎么办 正好压本科线该怎么办 大脚趾被砸了怎么办 脊柱侧弯每天疼怎么办 内衣扣的位置脊柱疼怎么办 练完瑜伽颈椎疼怎么办 乳胶枕头太高了怎么办 枕头太高脖子痛怎么办 颈椎突出症状缓解后怎么办 外痔疼的的历害怎么办 小肚子疼得历害怎么办 练瑜伽伤到颈椎怎么办 鼻子干口干胃烧怎么办 颈椎病压迫神经引起手麻怎么办 4个月婴儿睡觉少怎么办 晚上睡觉睡不好老是醒来怎么办 吃了没熟的香蕉怎么办 70岁父母老吵架怎么办 怀孕七个月晚上睡不着怎么办 九个月宝宝睡眠不好怎么办 一个月的宝宝放不下怎么办 宝宝被吓了发烧怎么办