#208 config.h.win32 error in Visual Studio 11

happens every time
open
nobody
5
2013-05-09
2012-05-02
govtgeek
No

config.h.win32, when renamed to config.h as instructed in the readme, will cause Visual Studio 11 to fail to build the project with error:

fatal error C1189: #error : keyword defined before including C++ standard header

Lines 141-144:
#ifdef CXX_HAS_BUGGY_FOR_LOOPS
/* #undef for */
#define for if(1) for
#endif

Commenting out the lines allows the project to build. Unknown if the 'buggy for loops' are an issue afterwards.

Discussion

  • Alan Carre
    Alan Carre
    2013-05-09

    It is not an issue in VS11 and hasn't been since Visual Studio 2005. The "buggy for" refers to improper scoping of variables declared in the for loop declaration:

    ex:
    /////////////////////////////
    //Buggy for loop example:
    //
    //THE FOLLOWING SHOULD NOT COMPILE!
    //=================================
    //But it does in VC6 which is non-compliant.
    //The output would be "10" in that case.
    /////////////////////////////
    #include <stdio.h>

    int main(int, ...) {
    for(int i=0;i<10;i++) {/* can access i in here ONLY */}
    return printf("%d", i);
    }

    The variable "i" should only be available inside the scope of the for loop.

    So if you replace "for" with if(1) for ...

    if(1) for(int i=0;i<10;i++) {}

    really looks like:

    if(1) {
    for(int i=0;i<10;i++) {
    //do some stuff
    }
    }

    i is not available here because it falls within case "1" (there is an invisible scope).

    ==================

    At least that's my best guess. Not sure how to test it on a compliant compiler.

    • Alan Carre
     
    Last edit: Alan Carre 2013-05-09