最近,我了解到
.bss
段存储未初始化的数据。然而,当我尝试以下的一个小程序并在终端中使用size(1)
命令时,.bss
段没有改变,即使我添加了一些全局变量。我是否有误解?jameschu@aspire-e5-573g:~$ cat test.c
#include <stdio.h>
int main(void)
{
printf("hello world\n");
return 0;
}
jameschu@aspire-e5-573g:~$ gcc -c test.c
jameschu@aspire-e5-573g:~$ size test.o
text data bss dec hex filename
89 0 0 89 59 test.o
jameschu@aspire-e5-573g:~$ cat test.c
#include <stdio.h>
int a1;
int a2;
int a3;
int main(void)
{
printf("hello world\n");
return 0;
}
jameschu@aspire-e5-573g:~$ gcc -c test.c
jameschu@aspire-e5-573g:~$ size test.o
text data bss dec hex filename
89 0 0 89 59 test.o
int big[1024]
或类似的内容。BSS 可能具有基本大小,仅包含三个变量而不会改变。 - Paul Ogilvie