Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build in Visual C++ without Microsoft extensions [duplicate]

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?

like image 275
Pietro Avatar asked Jul 10 '14 16:07

Pietro


1 Answers

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 :)

like image 112
Billy ONeal Avatar answered Nov 12 '22 22:11

Billy ONeal