Build in Visual C ++ without Microsoft Extensions

I am trying to create a project in Microsoft Visual C ++ 2013 by disabling all non-standard extensions.

#ifdef _MSC_VER #include <windows.h> #endif 

In the configuration properties → C / C ++ → Language, I set the “Prohibit language extensions” to “Yes” (/ Za).
However, while creating 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 an anonymous structure

This means that the _MSC_VER macro is still defined and "windows.h" is enabled.

How to include a file if and only if I use Visual C ++?

How can I install Visual C ++ so that it compiles the code as standard C ++, marking all Microsoft extensions as errors?

+6
source share
1 answer

How to include a file if and only if I use Visual C ++?

As you have already demonstrated by checking _MSC_VER .

How can I install Visual C ++ so that it compiles the code as standard C ++, marking all Microsoft extensions as errors?

You can not. I do not know about a compiler that allows this. Standards such as predefined macros for the compiler version are fully permitted by the standard, so they will not be disabled as "non-standard extensions."

If you want to verify that your program is built for other platforms, then create your program on other platforms. GCC and Clang will tell you that they accept much better than Visual C ++ :)

+2
source

Source: https://habr.com/ru/post/972036/


All Articles