Is there any way to know if I'm compiling under a specific Microsoft Visual Studio version?
7 Answers
_MSC_VER
and possibly _MSC_FULL_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++ 14.30 _MSC_VER == 1933 (Visual Studio 2022 version 17.3.4)
MSVC++ 14.30 _MSC_VER == 1932 (Visual Studio 2022 version 17.2.2)
MSVC++ 14.30 _MSC_VER == 1930 (Visual Studio 2022 version 17.0.2)
MSVC++ 14.30 _MSC_VER == 1930 (Visual Studio 2022 version 17.0.1)
MSVC++ 14.28 _MSC_VER == 1929 (Visual Studio 2019 version 16.11.2)
MSVC++ 14.28 _MSC_VER == 1928 (Visual Studio 2019 version 16.9.2)
MSVC++ 14.28 _MSC_VER == 1928 (Visual Studio 2019 version 16.8.2)
MSVC++ 14.28 _MSC_VER == 1928 (Visual Studio 2019 version 16.8.1)
MSVC++ 14.27 _MSC_VER == 1927 (Visual Studio 2019 version 16.7)
MSVC++ 14.26 _MSC_VER == 1926 (Visual Studio 2019 version 16.6.2)
MSVC++ 14.25 _MSC_VER == 1925 (Visual Studio 2019 version 16.5.1)
MSVC++ 14.24 _MSC_VER == 1924 (Visual Studio 2019 version 16.4)
MSVC++ 14.23 _MSC_VER == 1923 (Visual Studio 2019 version 16.3)
MSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 version 16.2)
MSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 version 16.1)
MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 version 16.0)
MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013 version 12.0)
MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012 version 11.0)
MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010 version 10.0)
MSVC++ 9.0 _MSC_FULL_VER == 150030729 (Visual Studio 2008, SP1)
MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008 version 9.0)
MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005 version 8.0)
MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)
MSVC++ 7.0 _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)
MSVC++ 6.0 _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)
MSVC++ 5.0 _MSC_VER == 1100 (Visual Studio 97 version 5.0)
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. A thorough list can be found here. Starting recently, Visual Studio will start updating its ranges monotonically, meaning you should check ranges, rather than exact compiler values.
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
.....

- 1,146
- 14
- 14

- 7,060
- 3
- 26
- 50
-
43Sorry, but why don't Microsoft make this information easy to find? this post is very useful but shouldn't be required. – ed_me Oct 01 '15 at 09:50
-
10It appear that this macro doesn't reflect the compiler version used by the project. I.e. if you open a VS2010 project in a newer version without upgrading the project this macro doesn't reflect the compiler being used - only the IDE version. – thomthom Feb 10 '16 at 11:08
-
1I'm in the process of compilinf libFLAC together with some other libraries. They require compilation to be done using toolset v100. There's a code `#if defined _MSC_VER # if _MSC_VER >= 1800 # include
`. inttypes.h cannot be found, though. Very strange – Bernhard Döbler Dec 30 '16 at 20:30 -
The place you linked to claims VS 2017 is MSVC++ version 15.0, but your answer claims it's MSVC++ 14.1. Which one is correct? – Pharap Aug 02 '17 at 15:14
-
2@thomthom : This macro exactly reflects the Toolset version used by the selected target of the build project. Or more distinct: Project->Properties->General->Platform Toolset. – Yamakuzure Nov 30 '17 at 11:57
-
9@chrisw We now document this at https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017, see ```_MSC_VER ```. Hope this helps – Sebastian Jan 01 '19 at 07:52
Yep _MSC_VER is the macro that'll get you the compiler version. The last number of releases of Visual C++ have been of the form <compiler-major-version>.00.<build-number>
, where 00 is the minor number. So _MSC_VER
will evaluate to <major-version><minor-version>
.
You can use code like this:
#if (_MSC_VER == 1500)
// ... Do VC9/Visual Studio 2008 specific stuff
#elif (_MSC_VER == 1600)
// ... Do VC10/Visual Studio 2010 specific stuff
#elif (_MSC_VER == 1700)
// ... Do VC11/Visual Studio 2012 specific stuff
#endif
It appears updates between successive releases of the compiler, have not modified the compiler-minor-version
, so the following code is not required:
#if (_MSC_VER >= 1500 && _MSC_VER <= 1600)
// ... Do VC9/Visual Studio 2008 specific stuff
#endif
Access to more detailed versioning information (such as compiler build number) can be found using other builtin pre-processor variables here.

- 5,241
- 1
- 29
- 51

- 2,035
- 1
- 14
- 10
-
-
@José, true we could simplify it to just check for VC++ 9 with `_MSC_VER_ == 1500`, however if MS, did modify the `_MSC_VER` with compiler updates, service packs, etc (I don't think they ever have), then the `== 1500` check could break. Which is why I've coded it that way. – display101 Dec 09 '13 at 17:02
-
__MSC_VER evaluate to the major and minor number components of the compiler's version. This will not change with an update, there is _MSC_FULL_VER with include the build number too, i have never need to use that. – José Dec 09 '13 at 17:46
-
-
_MSC_VER should be defined to a specific version number. You can either #ifdef on it, or you can use the actual define and do a runtime test. (If for some reason you wanted to run different code based on what compiler it was compiled with? Yeah, probably you were looking for the #ifdef. :))

- 951
- 5
- 8
As a more general answer http://sourceforge.net/p/predef/wiki/Home/ maintains a list of macros for detecting specicic compilers, operating systems, architectures, standards and more.

- 88,407
- 13
- 85
- 165
This is a little old but should get you started:
//******************************************************************************
// Automated platform detection
//******************************************************************************
// _WIN32 is used by
// Visual C++
#ifdef _WIN32
#define __NT__
#endif
// Define __MAC__ platform indicator
#ifdef macintosh
#define __MAC__
#endif
// Define __OSX__ platform indicator
#ifdef __APPLE__
#define __OSX__
#endif
// Define __WIN16__ platform indicator
#ifdef _Windows_
#ifndef __NT__
#define __WIN16__
#endif
#endif
// Define Windows CE platform indicator
#ifdef WIN32_PLATFORM_HPCPRO
#define __WINCE__
#endif
#if (_WIN32_WCE == 300) // for Pocket PC
#define __POCKETPC__
#define __WINCE__
//#if (_WIN32_WCE == 211) // for Palm-size PC 2.11 (Wyvern)
//#if (_WIN32_WCE == 201) // for Palm-size PC 2.01 (Gryphon)
//#ifdef WIN32_PLATFORM_HPC2000 // for H/PC 2000 (Galileo)
#endif

- 6,274
- 5
- 47
- 67
-
I like this answer a lot more than the top voted one. Because _MSC_VER requires that you include stdio.h – KANJICODER Sep 09 '17 at 16:22
-
2`_MSC_VER` does not require you to include `stdio.h`, which can be easily tested `echo int i = _MSC_VER; > tmp.c` `cl /nologo /c tmp.c` – Kevin Smyth Dec 18 '17 at 20:22
-
2@J.M.I.MADISON : Not only is it not true regarding _MSC_VER which is a _predefined macro_, this answer clearly does not answer the question - it detects the platform, not the compiler version version. – Clifford Oct 28 '19 at 21:37
In visual studio, go to help | about and look at the version of Visual Studio that you're using to compile your app.

- 58,045
- 14
- 90
- 114
-
7This can't be serious. Especially from someone with a reputation like this. I assume you were just making a joke? – BuvinJ Oct 05 '16 at 12:44
-
2I think he just interpreted the question in a different manner. After all, this is one of the first answers to the question. – Keith M Mar 17 '17 at 22:58
-
8AFAIK @Haacked is valid and correct, as the question does not include "from my code" or other statement telling that he/she is not already using a VS IDE. – Alex Byrth Apr 04 '18 at 20:26