I'm puzzled over this function.
int i;
for(i = 1; i<10; i++){
int arr[i];
printf("%d\n",sizeof(arr));
}
return 0;
How can the space grow in a bounded (by ESP) stack memory? Is there a sort of compilation trick?
EDIT for explanation: Shouldn't the stack be something like that?
0 ---> val of i uninitialized
-4 ---> arr[0] uninitialized
and after the first loop
0 ---> val of i uninitialized
-4 ---> arr[1] uninitialized
-8 ---> arr[0] uninitialized
I'm tempted to say: is ESP moving below each iteration of the loop?
On every loop there is allocated stack for the array and then dealocated.
A bit different example
in the compiled code
lines 15,19 & 20 allocate the space and thew line 28 deallocates the space for the array
https://godbolt.org/z/msgrc2