Boost logo

Boost :

From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2002-01-15 11:52:37

Hi All,

At least the MSVC++ 6.x compiler implements 'for' incorrectly. For example,
the following snippet fails to compile on MSVC++ 6.x:

    for (int i=0; i<10; ++i);
    for (int i=0; i<10; ++i); // incorrect double def of i

The problem is that MSVC++ treats the above code as if it had been written as:

    int i=0;
    for (; i<10; ++i) {}
    int i=0; // incorrect double def of i
    for (; i<10; ++i) {}

There is a simple widely known workaround for this bug:

    #ifndef for
    #define for if (0) {} else for

The biggest undesirable side-effect is that it may brake some legacy MSVC++
code that relies on the old incorrect behavior. On the other hand, such code
probably needs to be fixed sooner or later.

Would this be worth adding to the MSVC++ config files?

Boost list run by bdawes at, gregod at, cpdaniel at, john at