How the stack work?
Hi there,
I remember the stack starts from the top, which means the earlier local variable will be located at a higher address space.
I have the following code in the main() function in ARM-MDK IDE:
uint8_t v1;
uint8_t v2;
uint8_t v3;
LOG_DBG("&v1[%p] &v2[%p] &v3[%p]\r\n", &v1, &v2, &v3);
When I set the optimization to "Level 0(-O0)", the output is:
&v1[20000BEC] &v2[20000BE8] &v3[20000BE4]
While when I set the optimization to "Level 3(-O3)", the output change to:
&v1[20000BE4] &v2[20000BE8] &v3[20000BEC]
There are 2 questions in my eyes:
1. I define the variable as uint8_t, it should space only one byte, why are there 4 bytes?
2. why does the direction of the stack increment is different with different optimization options?
Thanks!
