Stack space - allocating local variables
Posted on 2005-04-15
When entering a function, does stack space get allocated for all local variables for that function even if they are burried in a if / else block? Or do local
variables only get pushed on the stack when they become "in scope" within
the function while the function is executing? For example:
Will space ever be allocated on the stack for the variable i in function2 since the if is never entered?
If so, there is no advantage to declaring your variables within a if block, right? It would be the same as declaring it at the beginning of the function. All
variables within the if / else blocks will be allocated on the stack even if
those blocks are never entered during program flow. Or do the variables
within the if blocks only get put on the stack if that block of code is
entered during execution?