相关疑难解决方法(0)

为什么需要.bss段?

我所知道的是全局和静态变量存储在.data段中,未初始化的数据存在于.bss段中.我不明白的是为什么我们有未初始化变量的专用段?如果未初始化的变量在运行时分配了值,那么该变量是否仅存在于.bss段中?

在以下程序中, a是在.data段中,并且b.bss段中; 那是对的吗?如果我的理解是错误的,请纠正我.

#include <stdio.h>
#include <stdlib.h>

int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9};
int b[20]; /* Uninitialized, so in the .bss and will not occupy space for 20 * sizeof (int) */

int main ()
{
   ;
}  
Run Code Online (Sandbox Code Playgroud)

另外,请考虑以下程序,

#include <stdio.h>
#include <stdlib.h>
int var[10];  /* Uninitialized so in .bss */
int main ()
{
   var[0] = 20  /* …
Run Code Online (Sandbox Code Playgroud)

c linux compiler-construction

107
推荐指数
6
解决办法
4万
查看次数

标签 统计

c ×1

compiler-construction ×1

linux ×1