Search code examples
c++visual-c++c-preprocessor

Is there a preprocessor define that is defined if the compiler is MSVC?


So I can do something like

#ifdef MSVC
//do compiler specific code here
#endif

Solution

  • It's _MSC_VER. More info at MSDN and at predef.

    But, be aware that some other compilers may also define it, e.g. Intel's C++ Compiler for Windows also defines _MSC_VER. If this is a concern, use #if _MSC_VER && !__INTEL_COMPILER.