how to detect if I'm compiling code under visua...

_MSC_VER is what you need. You can also examine visualc.hpp in any recent boost install for some usage examples.

Some values for the more recent versions of the compiler are:

MSVC++ 11.0 _MSC_VER = 1700 (Visual Studio 2012)

MSVC++ 10.0 _MSC_VER = 1600 (Visual Studio 2010)

MSVC++ 9.0  _MSC_VER = 1500 (Visual Studio 2008)

MSVC++ 8.0  _MSC_VER = 1400 (Visual Studio 2005)

MSVC++ 7.1  _MSC_VER = 1310 (Visual Studio 2003)

MSVC++ 7.0  _MSC_VER = 1300

MSVC++ 6.0  _MSC_VER = 1200

MSVC++ 5.0  _MSC_VER = 1100

The version number above of course refers to the major version of your Visual studio you see in the about box, not to the year in the name.

cl.exe /? will give a hint of the used version, e.g.:

c:\program files (x86)\microsoft visual studio 11.0\vc\bin>cl /?

Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86 ...

你可能感兴趣的:(how to detect if I'm compiling code under visua...)