Programming Tips - How do I use the _MSC_VER predefined macro?

Date: 2010may7 Updated: 2022oct28 Language: C/C++ Product: Visual C++ OS: Windows Q. How do I use the _MSC_VER predefined macro? A. The help file says:
Reports the major and minor versions of the compiler. For example, 1310 for Microsoft Visual C++ .NET 2003. 1310 represents version 13 and a 1.0 point release.
There is code around that seems to think its hex - eg 0x1310. This WRONG! (WINVER is like that.) The simplest way to use it is to test if you are using a Microsoft compiler or not:
#ifdef _MSC_VER // Using some version of Microsoft Visual C++ #else // NOT using Microsoft Visual C++ #endif
If you need to check the version, do this:
#if (_MSC_VER >= 1910) // This is Visual C++ 15.x (Visual Studio 2017) #elif (_MSC_VER >= 1400) // This is Visual C++ 8.x (Visual Studio 2005) #elif (_MSC_VER >= 1310) // This is Visual C++ 7.1 (Visual Studio .NET 2003) #elif (_MSC_VER >= 1300) // This is Visual C++ 7.0 (Visual Studio .NET 2002) #else // This is Visual C++ 6.0 or older #endif