C
Cristea Bogdan
Hi
I have started reading some old book of c programming (Peter van der Linden, Expert C Programming, Prentice Hall, 1994) and I have found the following statement: "initialized variables are allocated on the data segment of the program and uninitialized variables on the BSS segment".
Experimenting with a short program shows that this statement is no longer true:
It seems that only global variables go into BSS (regardless if they initialized or not), while static variables seem to be allocated at run time.
Below is the program used for tests:
#define SIZE (1<<20)
static char arrs[SIZE];
char arrg[SIZE] = {0};
int main()
{
return 0;
}
I have used gcc to compile using the default flags and size to check the segments size.
Could someone shed some light into this issue (how global and static variables are allocated) ?
thanks
Bogdan
I have started reading some old book of c programming (Peter van der Linden, Expert C Programming, Prentice Hall, 1994) and I have found the following statement: "initialized variables are allocated on the data segment of the program and uninitialized variables on the BSS segment".
Experimenting with a short program shows that this statement is no longer true:
It seems that only global variables go into BSS (regardless if they initialized or not), while static variables seem to be allocated at run time.
Below is the program used for tests:
#define SIZE (1<<20)
static char arrs[SIZE];
char arrg[SIZE] = {0};
int main()
{
return 0;
}
I have used gcc to compile using the default flags and size to check the segments size.
Could someone shed some light into this issue (how global and static variables are allocated) ?
thanks
Bogdan