{"id":10795,"date":"2016-10-05T11:00:36","date_gmt":"2016-10-05T18:00:36","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=10795"},"modified":"2019-02-18T18:04:39","modified_gmt":"2019-02-18T18:04:39","slug":"visual-c-compiler-version","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/visual-c-compiler-version\/","title":{"rendered":"Visual C++ Compiler Version"},"content":{"rendered":"<p><a href=\"https:\/\/docs.microsoft.com\/cpp\/preprocessor\/predefined-macros\">Official documentation on Predefined Macros<\/a> in Visual C++<\/p>\n<p><em>This blog was written by Gabriel Dos Reis and Mark Levine.<\/em><\/p>\n<p><span style=\"color: #000000;font-family: Calibri\">Starting with VS \u201c15\u201d Preview 5, the Visual C++ Team is monotonically updating the value of the built-in preprocessor macro <code>_MSC_VER<\/code> at every Visual C++ toolset update. <\/span><\/p>\n<h3>Why?<\/h3>\n<p>Thanks to the investments and progress that the Visual C++ Team has been making in the area of ISO C++ implementation conformance, we have been shipping new language features and introducing new conformance changes at a pace never seen before\u00a0 by our customers, in particular in updates to the Visual C++ toolset.\u00a0 As a result, it has become necessary for our customers to have a good way to differentiate between updates of VC++ (and not just major versions) within their source code.\u00a0 For instance, a program wanting to make use of the C++11 noexcept feature with VC++ would typically write:<\/p>\n<pre class=\"prettyprint\">\n#if _MSC_VER &gt;= 1900\n\/\/ \u2026 use noexcept here \u2026\n#endif\n<\/pre>\n<h3>How to Test?<\/h3>\n<p>Traditionally, developers write conditionally-included pieces of code testing the value of the built-in preprocessor macro <code>_MSC_VER<\/code> against known values indicating major releases of the Visual C++ compiler. For example,<\/p>\n<pre class=\"prettyprint\">\n_MSC_VER &gt;= 1900\n<\/pre>\n<p>tests for any version of the Visual C++ compiler released after VS2015 RTM. That continues to be our recommended practice. What we are doing, starting with VS \u201c15\u201d, is to increment the value of <code>_MSC_VER<\/code> at each update.<\/p>\n<p>To test for VC++ updates or releases after a given reference point, use the \u201c<code>&gt;=<\/code>\u201d (greater-or-equal) operator to compare <code>_MSC_VER<\/code> against that known reference value. Furthermore, if you have several reference points to compare against in a mutually exclusive manner, we recommend you order your comparisons in decreasing order of the reference values. For instance, the following snippet<\/p>\n<pre class=\"prettyprint\">\n#if _MSC_VER &gt;= 1900\n\/\/ \u2026\n#elif _MSC_VER &gt;= 1800\n\/\/ \u2026\n#else\n\/\/ \u2026\n#endif\n<\/pre>\n<p>checks for compilers released after VS2015, then compilers released after VS2013, then takes an action for all compilers released prior to VS2013.<\/p>\n<h3>Ordering Tests with &lt;<\/h3>\n<p>If you chose to use the less-than operator (<code>&lt;<\/code>), then we recommend that you order your tests in increasing order of the reference values.<\/p>\n<h3>Checking for A Specific Compiler Version<\/h3>\n<p>On very rare occasions, you might be looking for a specific VC++ release. Only in such circumstances would you need to use the equality operator \u201c<code>==<\/code>\u201d to compare <code>_MSC_VER<\/code> against a known value. Such circumstances include working around a bug in a well-known version of VC++. However, in general, we recommend you use the \u201c<code>&gt;=<\/code>\u201d and order your tests in decreasing order.<\/p>\n<h3>Looking for A Closed Set of Compiler Versions<\/h3>\n<p>Some circumstances require looking for a closed set of compiler versions. For instance, this code fragment<\/p>\n<pre class=\"prettyprint\">\n#if _MSC_VER &gt;= 1900 &amp;&amp; _MSC_VER &lt; 2000\n\t\u201cmspdb140.dll\u201d\n#endif\n<\/pre>\n<p>includes the string literal <code>\u201cmspdb140.dll\u201d<\/code> only when the compiler is from the VS2015 vintage. In these situations, you will use \u201c<code>&gt;=<\/code>\u201d and \u201c<code>&lt;<\/code>\u201d to construct a semi-open interval that delimits the release series you are interested in.<\/p>\n<h3>When Should I Use _MSC_FULL_VER Then?<\/h3>\n<p><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/b0084kay.aspx\"><code>_MSC_FULL_VER<\/code><\/a> is a more granular variant of the built-in preprocessor macro <code>_MSC_VER<\/code> that incorporates also the build number of the compiler. You would use this when you want to differentiate between micro-updates of the same update. Until now, it has also been used to differentiate between updates.<\/p>\n<h3>What About _MSC_BUILD?<\/h3>\n<p>It is a built-in preprocessor macro, documented <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/b0084kay.aspx\">here<\/a>, rarely used or needed in most C or C++ source code.<\/p>\n<h3>The Compiler Versioning Scheme<\/h3>\n<p>Each major release of the Visual C++ compiler increments the \u201chundreds\u201d of <code>_MSC_VER<\/code>. Each update within a major release increments the \u201cunits\u201d by 1. For example, in VS \u201c15\u201d Preview 5, the macro <code>_MSC_VER<\/code> evaluates to 1910. The next update will have <code>_MSC_VER<\/code> set to 1911.<\/p>\n<p>Note that VS \u201c15\u201d and VS2015 are both major releases of Visual Studio with different major version numbers. The included compiler toolset, however, will have the same major version number \u2013 with the change described here, the minor version number can be used to distinguish compiler toolsets.<\/p>\n<h3>Call to Action<\/h3>\n<p>If you have existing code that compares <code>_MSC_VER<\/code> using the equality operator, have a second look and see if that comparison is better expressed with the greater-or-equal operator as explained above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Official documentation on Predefined Macros in Visual C++ This blog was written by Gabriel Dos Reis and Mark Levine. Starting with VS \u201c15\u201d Preview 5, the Visual C++ Team is monotonically updating the value of the built-in preprocessor macro _MSC_VER at every Visual C++ toolset update. Why? Thanks to the investments and progress that the [&hellip;]<\/p>\n","protected":false},"author":321,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[340,303,341,342],"class_list":["post-10795","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-_msc_full_ver","tag-_msc_ver","tag-compiler-version-macro","tag-vc-versioning"],"acf":[],"blog_post_summary":"<p>Official documentation on Predefined Macros in Visual C++ This blog was written by Gabriel Dos Reis and Mark Levine. Starting with VS \u201c15\u201d Preview 5, the Visual C++ Team is monotonically updating the value of the built-in preprocessor macro _MSC_VER at every Visual C++ toolset update. Why? Thanks to the investments and progress that the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/10795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=10795"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/10795\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=10795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=10795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=10795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}