Search code examples
c++cmingwportabilitymingw-w64

Why does including <windows.h> result in "error: expected ')' before numeric constant" on an unrelated #define statement


Can anybody explain what is going wrong here? When I try to compile qtermwidget under MinGW-w64, and adding #include <windows.h> to source file BlockArray.cpp, I get the following compile error relating to #define BlockSize (1 << 12) in BlockArray.h:

In file included from E:/git/qtermwidget/lib/BlockArray.cpp:27: 
E:/git/qtermwidget/lib/BlockArray.h:30:20: error: expected ')' before numeric constant
30 | #define BlockSize (1 << 12)
   |                   ~^

Why is the addition of the windows.h header causing this error? Assuming I really want to add this header, can I change the #define BlockSize (1 << 12) in BlockArray.h somehow to not break the compile?


Solution

  • Thanks very much to Sam and busybee, I can confirm that there is a name conflict in winnt.h which is brought in via windows.h. It's a typedef using the 'BlockSize' name, rather than another preprocessor definition, however:

    typedef struct _TAPE_SET_MEDIA_PARAMETERS {
        ULONG BlockSize;
    } TAPE_SET_MEDIA_PARAMETERS, *PTAPE_SET_MEDIA_PARAMETERS;
    

    Changing the #define BlockSize (1 << 12) in BlockArray.h to a new name, e.g. #define LXQT_BlockSize (1 << 12) resolves the conflict.