I get unexpected output from the command size.
Afaik initialized global and static variables stored in the segment data, not initialized and initialized to 0 global / static variables stored in the segment bss.
printf("%d",sizeof(int));It gives the size int4. However segment bssand datadoes not increase to 4 respectively.
int main()
{
return 0;
}
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin>size memory-layout.exe
text data bss dec hex filename
10044 2292 2512 14848 3a00 memory-layout.exe
int g; //uninitialised global variable so, stored in bss segment
int main()
{
return 0;
}
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin>size memory-layout.exe
text data bss dec hex filename
10044 2292 2528 14864 3a10 memory-layout.exe
why bssincreased by 16 (2528 - 2512) instead of 4? (in the code above)
#include <stdio.h>
int g=0;
int main()
{
return 0;
}
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin>size memory-layout.exe
text data bss dec hex filename
10044 2292 2512 14848 3a00 memory-layout.exe
there is bssno increment despite using a global variable. Why is this?
#include <stdio.h>
int main()
{ static int g;
return 0;
}
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin>size memory-layout.ex
text data bss dec hex filename
10044 2292 2512 14848 3a00 memory-layout.exe
no segment increment bssdespite using a static variable, why?
, dec?