VC6 is rather old, and not always ... rigid ... in its application of the standard :-) It actually leaked scope in certain circumstances like:
for (int i = 0; i < 10; i++) { }
// You can still use 'i' here.
This led to some funky macro magic to get around this problem. If you're using a ISO-conformant compiler, both those things you try to do are illegal.
From ISO C++11 3.3.3/1
, dealing with the introduction of block scope with {...}
:
A name declared in a block is local to that block; it has block scope. Its potential scope begins at its point of declaration and ends at the end of its block.
Section 6.5.3
covers the scope of variables "created" by a for
statement:
If the for-init-statement
is a declaration, the scope of the name(s) declared extends to the end of the for-statement
.