Variable Scope in MSVC++ 6
I recently tried to compile one of the programs I'd written with GCC under MSVC++. This is not the program I wrote, but an example of the problem.
Code:
for (int i = 0; i < 10; i++)
{
std::cout << i << std::endl;
}
for (int i = 10; i > 0; i--)
{
std::cout << i << std::endl;
}
For some reason, VC++ gives the variable "i" the scope of the code block instead of the for loop. Thus, the second declaration of "i" throws an error, while it shouldn't, as "i" should be local to the for loop.
So far, the only solution I have found is to put the loops within their own code blocks.
Code:
{
for (int i = 0; i < 10; i++)
{
std::cout << i << std::endl;
}
}
{
for (int i = 10; i > 0; i--)
{
std::cout << i << std::endl;
}
}
This looks nasty and is something of a pain.
First off, is this fixed in VS.NET? Second off, is there any way to correct MSVC++ 6's behavoir?