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

C++Visual C++C Preprocessor

C++ Problem Overview


So I can do something like

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

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

Look at the list of MSVC predefined macros. You'll find what you need.

_MSC_VER is probably a good one.

Solution 3 - C++

_MSC_VER should fit your needs

Solution 4 - C++

_MSC_VER is one such predefined macro.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAvery3RView Question on Stackoverflow
Solution 1 - C++Alexey KukanovView Answer on Stackoverflow
Solution 2 - C++MatView Answer on Stackoverflow
Solution 3 - C++mbxView Answer on Stackoverflow
Solution 4 - C++Will AView Answer on Stackoverflow