I am using a test program to understand the C memory model on Linux 6.3 with kernel version 2.6.32-279.el6.x86_64.
First I compile the code below,
#include <stdio.h>
int main(void)
{
static int i = 100;
return 0;
}
when running the size command, I got below
[root@rachitjain jan14]
text data bss dec hex filename
1040 488 16 1544 608 a.out
then after removing intialization for static variable i, my code will be,
include <stdio.h>
int main(void)
{
static int i ;
return 0;
}
When you run the size after compiling above,
[root@rachitjain jan14]
text data bss dec hex filename
1040 484 24 1548 60c a.out
There is an 8-byte step in the bss section, but only 4 bytes are reduced in the data section. Why is the size an integer when doubling when moving to the bss segment?
I tested this symbol and swam, observed the same behavioral.
source
share