[ODE] OPCODE messing with variable scope? (MSVC6)

Aras Pranckevicius nearaz at interamotion.com
Thu Sep 25 10:11:37 MST 2003


> If I have something like:

What you are actually doing is against C++ spec. According to spec, loop
variable scope is only the loop itself (so you should have 'int i' in the
second loop).

> I get "error C2065: 'i' : undeclared identifier" from MSVC6 at the start
> of the second loop, as if the first declaration of i (at the start of
> the first loop) gives it scope that is internal to the first loop only.
> If I leave out #include "Opcode.h" this does not happen.

Now, what MSVC does is incorrect, according to spec - in MSVC, loop variable
scope starts in the loop, but doesn't end at loop ending. I vaguely remember
there is a compiler option to turn on "compliant loops", but this off by
default because lots of old code relies on non-conformant scope.

> Could something in OPCODE's headers be changing a compiler setting?

What OPCODE does is a #define for "for" that puts scope around for loops,
like this:
  #define for if(0){} else for
This is easily optimized-out by compiler, and gives standard compliant
scope.


Aras Pranckevicius aka NeARAZ
http://www.gim.ktu.lt/nesnausk/nearaz/



More information about the ODE mailing list