一、
#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
#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文件的大小受调试状态下编译的影响,但是段的大小不受影响。