compiler problem

  • Thread starter Thread starter DR
  • Start date Start date
D

DR

void a()
{
for (int i = 0; i <100; i++)
{
....
}
....
for (i = 0; i <100; i++) <-- ERROR
{
....
}
}

The VC++ 2005 compilers says "i undeclared identifer". Why?
 
i is out of scope after the end of the first for loop. There was a time
when some compilers would allow i to be in scope after the 1st for loop
had ended but the C++ standard (see section 6.5.3) does not allow this
behaviour any more. You can tell the compiler using /Ze that you want i
to be in scope after the end of the loop. Personally I would change my
code so that it was standard compliant.
 
sashan said:
i is out of scope after the end of the first for loop. There was a time
when some compilers would allow i to be in scope after the 1st for loop
had ended but the C++ standard (see section 6.5.3) does not allow this
behaviour any more. You can tell the compiler using /Ze that you want i
to be in scope after the end of the loop. Personally I would change my
code so that it was standard compliant.

In Visual C++ 2005 the option to revert back to the old non-conformant
behavior is:

/Zc:forScope-
 
In Visual C++ 2005 the option to revert back to the old non-conformant
behavior is:

/Zc:forScope-
--

I figured that out.

I'll report a bug:
The /W0 option seams to be ignored by the VC++2005Exp compiler . I still get
warnings.
 
Back
Top