How to determine the uncertainty of _MSC_VER?

I work in Visual Studio, but my project is for a POSIX-based environment (marmalade sdk). In this project, the build release is compiled using gcc for ARM, but the debug version works on Windows and is compiled by the MS compiler. In addition, this environment has its own implementation of STL and other standard libraries.

Many of these C ++ libraries have this code:

#if defined( _MSC_VER ) #include <Windows.h> #else #include <pthread.h> #endif 

Is it possible to define the _MSC_VER macro? - For C ++ libraries to discover the POSIX system here.

+3
source share
2 answers

Sure:

 #undef _MSC_VER #if defined( _MSC_VER ) #include <Windows.h> #else #include <pthread.h> #endif 

Or, #undef before including a file that uses _MSC_VER .

+2
source

_MSC_VER (and should always be) is defined when compiling with the Microsoft compiler, so that it "evaluates the major and minor components of the compiler version number". Therefore, the code uses the wrong macro test, because it will always be defined for some value for your compiler, regardless of differences in the Windows environment.

Instead of destroying the _MSC_VER definition (which could lead to other problems if some code really wants to know the version of the compiler), you should instead correct the condition to use a more suitable macro test that distinguishes between the types of Windows environments with which you could collide.

See a more complete list of predefined macros that you can consider here.

http://msdn.microsoft.com/en-us/library/vstudio/b0084kay.aspx

You can either replace the condition ...

#if someOtherConditionGoesHere

... or renew it with additional conditions, for example

#if defined (_MSC_VER) && & someOtherConditionGoesHere

+4
source

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


All Articles