为什么注释掉一个初始化的全局变量会从数据段中丢失4个字节的数据,而注释掉一个未初始化的全局变量会丢失来自BSS段的8个字节的数据?
PROGRAM1:
#include <stdio.h>
int global1 = 20; /* initialized global variable stored in DS*/
int global2; /* Uninitialized global variables stored in BSS segment*/
int global3=0; /* Global variables initialized to zero are stored in BSS*/
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
static int j=0; /* Static variables initialized to 0 are stored in bss*/
//int l=100; /* stack stores the auto variables*/
int k; /* stack stores the auto variables*/
return 0;
}
数据:504 BSS 32
程序2:
#include <stdio.h>
//int global1 = 20; /* initialized global variable stored in DS*/
int global2; /* Uninitialized global variables stored in BSS segment*/
int global3=0; /* Global variables initialized to zero are stored in BSS segment*/
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
static int j=0; /* Static variables initialized to 0 are stored in BSS segment*/
//int l=100; /* stack stores the auto variables*/
int k; /* stack stores the auto variables*/
return 0;
}
数据:500,BSS 32
节目3:
#include <stdio.h>
//int global1 = 20; /* initialized global variable stored in DS*/
//int global2; /* Uninitialized global variables stored in BSS segment*/
int global3=0; /* Global variables initialized to zero are stored in BSS segment*/
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
static int j=0; /* Static variables initialized to 0 are stored in BSS segment*/
//int l=100; /* stack stores the auto variables*/
int k; /* stack stores the auto variables*/
return 0;
}
数据500,BSS 24(为什么24,为什么不是28?)