I am using a test program for understanding C memory model on linux 6.3 with kernal version 2.6.32-279.el6.x86_64 .
First i have compile below code,
#include <stdio.h>
int main(void)
{
static int i = 100; /* Initialized static variable stored in DS*/
return 0;
}
on running size command , i got below ,
[root@rachitjain jan14]# size a.out
text data bss dec hex filename
1040 488 16 1544 608 a.out
then, after removing the intialization for static variable 'i' , my code becomes ,
include <stdio.h>
int main(void)
{
static int i ;
return 0;
}
On running size on after compiling above ,
[root@rachitjain jan14]# size a.out
text data bss dec hex filename
1040 484 24 1548 60c a.out
There is 8 byte increment in bss section but only 4 bytes are reduced in the data section. Why the size is integer in getting doubled while moving to bss segment ?
I have tested this character and float as well , observed the same behavioral.