Does anyone know a way around the multiple initialization error caused by code similar to the following?
for(int i=0;i<10;i++)
.
.
.
for(int i=0;i<20;i++)
Throws the following error on compile:
error C2374: 'i' : redefinition; multiple initialization
Scoping rules would, by my understanding, dictate that this syntax is legal as long as the second for statement above was not nested inside the first such as:
for(int i=0;i<10;i++)
{
for(int i=0;i<20;i++)
}
Therfore the scope of i in the 1st example would only be for the life of the first for statement, it should then be able to be used again. However, VC++ 6 throws the error.
Now if you do the same thing dropping the type on the second for loop it works fine
for(int i=0;i<10;i++)
.
.
.
for(i=0;i<20;i++) //notice no type, using 1st reference
Or, and here is the kicker. If you do nest it, in which case the scoping should be an issue, shown below, it works fine.
for(int i=0;i<10;i++)
{
for(int i=0;i<20;i++)
}
Someone had mentioned to me that they thought this was a known issue? True? Someone please give me a sanity check, maybe I have been staring at the screen too long. If this is the case I am not a happy camper. We have some code based on an API that needs to compile under both x86 and UNIX. This code compiles fine under Sun Forte C++. I am not looking forward to crawling code and change for loop variable names.
for(int i=0;i<10;i++)
.
.
.
for(int i=0;i<20;i++)
Throws the following error on compile:
error C2374: 'i' : redefinition; multiple initialization
Scoping rules would, by my understanding, dictate that this syntax is legal as long as the second for statement above was not nested inside the first such as:
for(int i=0;i<10;i++)
{
for(int i=0;i<20;i++)
}
Therfore the scope of i in the 1st example would only be for the life of the first for statement, it should then be able to be used again. However, VC++ 6 throws the error.
Now if you do the same thing dropping the type on the second for loop it works fine
for(int i=0;i<10;i++)
.
.
.
for(i=0;i<20;i++) //notice no type, using 1st reference
Or, and here is the kicker. If you do nest it, in which case the scoping should be an issue, shown below, it works fine.
for(int i=0;i<10;i++)
{
for(int i=0;i<20;i++)
}
Someone had mentioned to me that they thought this was a known issue? True? Someone please give me a sanity check, maybe I have been staring at the screen too long. If this is the case I am not a happy camper. We have some code based on an API that needs to compile under both x86 and UNIX. This code compiles fine under Sun Forte C++. I am not looking forward to crawling code and change for loop variable names.