This is the question:
How are variable length arrays implemented at machine code (or assembly code - I don't literally want to see some binary code) level? Since many local variables are stored in the .data
segment, I guess something different must be done to support VLAs.
Here is an experiment I did which didn't help me find the answer:
I tried to obtain some clues as to the answer to this question by writing a very short code in C, and then disassembling the compiled output.
Here is that code:
1 int main()
2 {
3
4 int n = 255;
5
6 int array[n];
7
8 array[0] = 15;
9
10 }
Compiled with gcc main.c
. Disassembled with objdump a.out -M intel -d
. Note, it might be the case that I could have used some better compiler options or options to the objdump command which would have made the output simpler, but I am not sure what these might be.
The output produced was significantly longer than I had initially expected, and looking through it I didn't find anything obvious which was able to answer the question.