[ODE] Simple macro trick to fix the compile problem with msvc 6

Chris Klein cdkode at ennui.dnsalias.net
Tue Jan 14 15:03:02 2003


On Tue, 14 Jan 2003, Sébastien Duval wrote:

> for ( int i = 0; i < 5; i ++ )
> {
>     // Do whatever...
> }
>
> for ( int i = 10; i < 35; i ++ )
> {
>     // Do something else...
> }

I do cross-platform development, and I am very familiar with this
problem.

> I propose to add a simple macro in ode.h
>
> #ifdef MSVC
> #define for  if (0) {} else for
> #endif
>
> This way, for loops will be in a seperate scopes.

Not to be too blunt, but I believe that this sort of hack has no place in
a library like ODE, and that goes doubly for a header file that a lot of
application code is going to include.

The MSVC6 variable declaration scope issue is well-known and so very easy
to avoid without giving the precompiler permission to rewrite every for
loop I create, and adding a useless if check that might - but probably
doesn't - get optimized out.

A better, but almost as unpleasant a hack would be to leave the if out of
it, and put the for inside its own { } scope using your #define for
method.  But, there are a lot of tools out there that parse C++ code for
various reasons, but don't include  precompiler functionality - can you
guarantee they are all unaffected by this?

> My two cents,
>
> Sébastien Duval, Insane Logics

I think you just gave me a few grey hairs.

A more palatable way to deal with this problem (and I'll have to deal with
it soon, as I move my own project code to msvc 6) would be to give Russell
a patch and explain what he needs to do to avoid this problem.


--Chris Klein