Is there a clean way to prevent windows.h from creating a near & far macro?

You can safely undefine them, contrary to claims from others. The reason is that they’re just macros’s. They only affect the preprocessor between their definition and their undefinition. In your case, that will be from early in windows.h to the last line of windows.h. If you need extra windows headers, you’d include them after windows.h and before the #undef. In your code, the preprocessor will simply leave the symbols unchanged, as intended.

The comment about older code is irrelevant. That code will be in a separate library, compiled independently. Only at link time will these be connected, when macros are long gone.

Leave a Comment