Question about stack and C++ scope.
I wrote long function with lots of scope {} for error handling.
On the top of function, stack is allocated for all variables
even inside of scope.
On Console examples.
LOCAL_C void doExampleL() {
int rc;
console->Printf(_L("Start Example\n"));
On entering doExampleL() function stack should be allocated for "int rc"(4byte) and return pointer(4byte). But stack is allocated for fp(200byte?) and msg1(1024byte).
I tested WINS build for VC7. I use Visual Studio.NET as bugger.
When entering doExampleL() function, Stack pointer(ESP register) consume over 1K byte.
That means scoping does not help for reducing stack size.
Do you know how to reduce stack size with scoping?
Generally, {} only applies to visibility scoping, not allocation scoping. A stack allocation frame for a function is calculated at compile time (usually) and it applies to the whole function, not a single {} block.
To save on stack usage, put portions of your function in separate functions, or simply use heap-based buffers.