Guru said:
Hai,
Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.
Bye
Guru Jois
Hi guru
How lcc-win32 allocates memory to variables
-------------------------------------------
For lcc-win32 there are several types of variables:
1) File scope variables, that are allocated in the initialized variables
section of the executable. For example:
int table[] = {1,2,3,4,5,6};
Lcc-win32 will reserve space in the data section for six 32 bit
numbers and initialize that to the binary values given.
Each object code file (.obj) can contain contributions to this
segment. The linker combines them all into a single segment.
2) File scope variables without any initial values. For example:
int table[6];
Lcc-win32 will reserve space for 6 32 bit numbers in the
uninitialized variable section (bss) and the value of them will be
set to zero when the system loads the program into memory.
3) Local variables.
They are allocated into a memory block reserved for temporary
storage. This is normally the stack segment. At entry of a function,
its activation record will be built, and the stack will be adjusted
to contain space for all local variables of the function. This
storage will be reclaimed when the function exits.
4) Variable length automatic variables
This variables will be allocated in the stack in a similar way as
(3) but they are not part of the activation frame since the
activation frame is fixed length, and this variables are variable
length. Example:
int fn(int n)
{ int table[n]; // <<<--- variable length array (VLA)
}