I have a question about the following C code:
void my_function()
{
int i1;
int j1;
// Do something...
if (check_something())
{
int i2;
int j2;
// Do something else...
}
// Do some more stuff...
}
Are there any guarantees about when stack space is allocated/deallocated for i2 and j2 or does it depend on the compiler? I would expect the stack pointer to be adjusted down when i2 and j2 come into scope and adjusted back up when they go out of scope, but then thought some compilers may just "optimize" the whole thing and account for variables in a nested scope when the function is first entered.
I know I can look at the assembly code generated by my compiler, but was wondering if the implementation can be left up to the compiler.
Thanks!