I am trying to build a project in Microsoft Visual C++ 2013 disabling all non standard extensions.
#ifdef _MSC_VER
#include <windows.h>
#endif
In Configuration Properties --> C/C++ --> Language, I set "Disable Language Extensions" to yes (/Za).
However, building the previous code I get errors such as:
C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(11527): error C2467: illegal declaration of anonymous 'struct'
This means that the _MSC_VER macro is still defined, and "windows.h" has been included.
How can I include a file if and only if I am using Visual C++?
How can I set Visual C++ so that it compiles the code as Standard C++, marking all Microsoft extensions as errors?
How can I include a file if and only if I am using Visual C++?
As you have already demonstrated, by checking _MSC_VER
.
How can I set Visual C++ so that it compiles the code as Standard C++, marking all Microsoft extensions as errors?
You can't. I'm not aware of any compiler that allows this. Things like predefined macros for compiler version are entirely allowed by the standard, so they wouldn't be disabled as "nonstandard extensions."
If you want to check that your program builds for other platforms, then build your program on other platforms. GCC and Clang will tell you what they accept far better than Visual C++ will :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With