lets say I have a file test.c that contains:
char buffer1[1024];
int somefunction()
{
char buffer2[1024];
// do stuff
}
now I know buffer2 is allocated on the stack on the frame belonging to somefunction calls, but where is buffer1 allocated ?
buffer1
has memory reserved in the static(bss/data) memory section of the program. That's where all statics and globals exist.It is a third memory segment, like the stack and the heap.
These variables are typically on BSS (variables which don't have explicit initialization in the source code, so they get the value 0 by default) or data segment (initialized datas). Here,
buffer1
is uinitialized, so it will probably be allocated on BSS segment, which starts at the end of the data segment.From bravegnu website:
An array declared statically would have different storage specification from an array declared locally. As you said, a local array
buffer2
will be (usually)created on stack while a static arraybuffer1
will be (usually)created on./bss
or./data
segments.