This will be extremely dependent on the compiler and optimization level. Some compilers might say that if-block would never be reached, and thus would not generate code for it at all. Others will be. Others may depend on the level of optimization. Still others allocate space for all local variables when calling a function, not when entering a region, because it is "easier" to calculate. This actually looks like the behavior of vanilla C, since there you SHOULD declare all the variables at the beginning of the functions (not sure if the spanning regions with local scale variables exist in vanilla C, they have been around for a long time), so this could be a deterrent.
In addition, you are obviously faced with the fact that the FAR stack is smaller than the heap, and how the declaration of a local variable may exceed its capacity, but I'm sure the intent of your example.
If you are looking for the best βwhy they did itβ, then publish the version (and settings) of the compiler that you use for this, and perhaps one of the authors will answer. Without this, who knows?
source share