AFAIK, there're 2 types of global variables, initialized and unintialized. How are they stored? Are they both stored in the executable file? I can think of initialized global variables having their initial values stored in executable file. But what needs to be stored for the uninitialized ones?
My current understanding is like this:
Executable file is organized as several sections, such as .text, .data, and .bss. Code is stored in .text section, initialized global or static data is stored in .data section, and uninitialized global or static data is stored in .bss section.
Thanks for your time to view my questions.
Update 1 - 9:56 AM 11/3/2010
I found a good reference here:
Update 2 - 10:09 AM 11/3/2010
@Michael
I define a 100 bytes of un-initialized data area in my assembly code, this 100-bytes is not stored in my executable file because it is NOT initialized.
Who will allocate the 100-byte uninitialized memory space in RAM? The program loader?
Suppose I got the following code:
int global[100];
void main(void)
{
//...
}
The global[100] is not initialzed. How will the global[100] be recoded in my executable file? And who will allocate it at what time? What if it is initialized?