{"id":26562,"date":"2020-09-14T16:30:16","date_gmt":"2020-09-14T16:30:16","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=26562"},"modified":"2021-06-08T18:02:31","modified_gmt":"2021-06-08T18:02:31","slug":"c11-and-c17-standard-support-arriving-in-msvc","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/c11-and-c17-standard-support-arriving-in-msvc\/","title":{"rendered":"C11 and C17 Standard Support Arriving in MSVC"},"content":{"rendered":"<p><em>Please see our <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/a-multitude-of-updates-in-visual-studio-2019-version-16-8-preview-3\/\">Visual Studio 2019 version 16.8 Preview 3 release notes<\/a> for more of our latest features.<\/em><\/p>\n<p><em>Update: Windows 10 SDK version 2104 has been released, which includes the changes needed for C11 and C17 as well as the conformant preprocessor. It can be downloaded <a href=\"https:\/\/developer.microsoft.com\/en-us\/windows\/downloads\/sdk-archive\/\">here<\/a>. To use this SDK, follow the instructions from step 3.<\/em><\/p>\n<p>Our team is happy to announce that C11 and C17 are becoming supported language versions in the MSVC compiler toolset starting with Visual Studio 2019 version 16.8 Preview 3!<\/p>\n<p>For many years Visual Studio has only supported C to the extent of it being required for C++. Things are about to change now that a conformant token-based preprocessor has been added to the compiler. With the advent of two new compiler switches, <code>\/std:c11<\/code> and <code>\/std:c17<\/code>, we are officially supporting the latest ISO C language standards.<\/p>\n<h3>What\u2019s in:<\/h3>\n<p>All the required features of C11 and C17 are supported. This meant adding the following functionalities:<\/p>\n<ul>\n<li><code>_Pragma<\/code><\/li>\n<li><code>restrict<\/code><\/li>\n<li><code>_Noreturn<\/code> and <code>&lt;stdnoreturn.h&gt;<\/code><\/li>\n<li><code>_Alignas<\/code>, <code>_Alignof<\/code> and <code>&lt;stdalign.h&gt;<\/code><\/li>\n<li><code>_Generic<\/code> and <code>&lt;tgmath.h&gt;<\/code> support<\/li>\n<li><code>_Static_assert<\/code><\/li>\n<\/ul>\n<p>IntelliSense works natively with these features as well, simply use a <code>.c<\/code> file extension for your source files or the <code>\/TC<\/code> compiler switch to enable syntax highlighting for C code.<\/p>\n<p><img decoding=\"async\" width=\"348\" height=\"49\" class=\"wp-image-26564\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image.png 348w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-300x42.png 300w\" sizes=\"(max-width: 348px) 100vw, 348px\" \/><\/p>\n<p>Currently IntelliSense highlighting is only available for the keywords and not the macros introduced by the standard headers. This will be fixed in a later release.<\/p>\n<p>Since C17 is essentially just a bug fix release of ISO C, with many defect reports being adopted, our support for C11 already includes all the relevant defect reports. At present, there are no differences between the C11 and C17 versions except for the <code>__STDC_VERSION__<\/code> macro, which expands to <code>201112L<\/code> (for C11) and <code>201710L<\/code> (for C17).<\/p>\n<p>Here is an example that shows these features:<\/p>\n<pre class=\"prettyprint\">#include &lt;assert.h&gt; \r\n#include &lt;stdalign.h&gt; \r\n#include &lt;stdlib.h&gt; \r\n#include &lt;stdnoreturn.h&gt; \r\n\r\n#define NO_WARN(X)                                                  \\\r\n    _Pragma(\"warning (push)\") _Pragma(\"warning (disable: 4146)\") X; \\\r\n    _Pragma(\"warning (pop)\") \r\n\r\n\/\/ Pick stored or storei based on the type of the dst \r\n#define store(x, y) _Generic((x),               \\\r\n                            data*: stored,      \\\r\n                            int* : storei)(x, y) \r\n\r\ntypedef struct data {\r\n    _Alignas(8) unsigned int i;\r\n} data;\r\n\r\nstatic_assert(alignof(data) == 8, \"data is not properly aligned\");\r\n\r\nvoid stored(data* restrict dst, const data* restrict src)\r\n{\r\n    \/\/ Do not trigger warning 4245 \r\n    dst-&gt;i = NO_WARN(-(src-&gt;i));\r\n\r\n}\r\n\r\nvoid storei(int* restrict dst, const int* restrict src)\r\n{\r\n    *dst = *src;\r\n}\r\n\r\n\r\nnoreturn void my_exit(int ret) {\r\n    exit(ret);\r\n}\r\n\r\nint main() {\r\n    data src, dst;\r\n    src.i = 5;\r\n\r\n    int i, j;\r\n\r\n    i = 10;\r\n\r\n    store(&amp;src, &amp;dst);\r\n    store(&amp;i, &amp;j);\r\n\r\n    my_exit(0);\r\n}<\/pre>\n<p>Since the inclusion of the token-based <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/announcing-full-support-for-a-c-c-conformant-preprocessor-in-msvc\/\">conformant preprocessor<\/a>, the two new C compiler switches imply <code>\/Zc:preprocessor<\/code>. If you want to use the traditional, character-based preprocessor alongside C11 or C17, you will need to pass in the <code>\/Zc:preprocessor-<\/code> compiler switch explicitly. We do encourage you to fix your source code where needed to not depend on the legacy, traditional preprocessor.<\/p>\n<h3>What\u2019s not:<\/h3>\n<div>While there is currently no support for any C11 optional features, we are committed to providing the most impactful optional features in future releases. Atomic and threading support are on our roadmap. Support for Complex numbers is currently not planned and their absence is enforced with the proper feature test macros. Please go to <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">Visual Studio Developer Community<\/a> and voice your support for features you wish to be implemented. We are looking for your input that we are making the correct prioritizations.<\/div>\n<div><\/div>\n<div><span style=\"font-size: 1rem;\">Due to the nature of the Windows heap, <\/span><code>aligned_alloc<\/code><span style=\"font-size: 1rem;\"> support is missing. The alternative is to use <\/span><a style=\"background-color: #f7f7f9; font-size: 1rem;\" href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/c-runtime-library\/reference\/aligned-malloc?view=vs-2019\">_aligned_malloc<\/a><span style=\"font-size: 1rem;\">.<\/span><\/div>\n<div><\/div>\n<p>Additionally, DR 400 support is currently unimplemented for <code>realloc<\/code> as this change would break ABI.<\/p>\n<h4>Variable Length Arrays<\/h4>\n<p>Astute readers will note that VLAs are also not supported. Variable length arrays are generally less efficient than comparable fixed sized arrays, and generally inefficient compared to equivalent <code>malloc()<\/code>, when safely and securely implemented. VLAs provide attack vectors comparable to those of the infamous <code>gets()<\/code> &#8212; deprecated and destined to removal &#8212; for opportunities of \u201cshifting the stack\u201d and other exploits. For these reasons we intend not to support VLAs as an optional feature in C11.<\/p>\n<h3>C11 and C17: Getting Started<\/h3>\n<p>In order to use C11 or C17 in your programs, the latest Windows SDK updates are required to work properly with the conforming preprocessor (<code>\/Zc:preprocessor<\/code>), and the new Universal C Runtime. Windows SDK releases correspond with Windows OS releases. Since there has been no Windows release with these changes, you will need an Insider Preview Windows SDK \u2013 a preview version of the Windows SDK that corresponds with Windows builds currently being flighted for Windows Insiders. Note that after installing the Insider Preview Windows 10 SDK, Visual Studio projects configured to use the latest Windows SDK will use the Insider Preview.<\/p>\n<h4>Step 1: Log in with an Insider Microsoft Account<\/h4>\n<p>Anyone can create a free Microsoft account (<a href=\"https:\/\/signup.live.com\/\">https:\/\/signup.live.com\/<\/a>) and then opt into the Insider program. Simply go to <a href=\"https:\/\/insider.windows.com\/en-us\/for-developers\">https:\/\/insider.windows.com\/en-us\/for-developers<\/a> and click \u2018Register\u2019 and log in.<\/p>\n<p><img decoding=\"async\" width=\"624\" height=\"372\" class=\"wp-image-26565\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-1.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-1.png 624w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-1-300x179.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>After registering, you will be given the option to start flighting Insider versions of Windows, but this is not necessary to download and use the Insider Windows 10 SDK. Registering does not automatically opt in your machines to download new Windows flights.<\/p>\n<p><img decoding=\"async\" width=\"624\" height=\"194\" class=\"wp-image-26566\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-2.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-2.png 624w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-2-300x93.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>Once you hit this page, you do <strong>not<\/strong> need to click \u2018Flight now\u2019. Continue to the next step and download the Insider Preview Windows 10 SDK.<\/p>\n<h4>Step 2: Download the Insider Preview Windows 10 SDK<\/h4>\n<p>The Insider Preview Windows SDK can be installed from <a href=\"https:\/\/www.microsoft.com\/en-us\/software-download\/windowsinsiderpreviewSDK\">https:\/\/www.microsoft.com\/en-us\/software-download\/windowsinsiderpreviewSDK<\/a>. If this is not the page you receive, make sure you are logged in with your Microsoft account that has been opted into being an Insider.\n<img decoding=\"async\" width=\"668\" height=\"421\" class=\"wp-image-26567\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-3.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-3.png 668w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-3-300x189.png 300w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/p>\n<p>The Insider page describes that using a Windows 10 Insider Preview OS is required. This is true for some of the content included in the Windows SDK, as they may depend on new APIs not present on older versions of Windows, but the Windows and Universal C Runtime headers will properly install and be usable without an Insider OS.<\/p>\n<p>Click \u2018Get SDK Insider Preview \u2013 Build 20206\u2019 to begin download. Future versions of the Windows SDK will also work.<\/p>\n<h4>Step 3: Install the Insider Preview Windows 10 SDK<\/h4>\n<p>The Insider Preview Windows SDK will download as an <code>.iso<\/code> file.<\/p>\n<p><img decoding=\"async\" width=\"1100\" height=\"582\" class=\"wp-image-26568\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-4.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-4.png 1100w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-4-300x159.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-4-1024x542.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-4-768x406.png 768w\" sizes=\"(max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>Mount the <code>.iso<\/code> file and run WinSDKSetup.exe to start installation.<\/p>\n<p><img decoding=\"async\" width=\"1086\" height=\"525\" class=\"wp-image-26569\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-5.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-5.png 1086w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-5-300x145.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-5-1024x495.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-5-768x371.png 768w\" sizes=\"(max-width: 1086px) 100vw, 1086px\" \/><\/p>\n<p>Choose to install the Windows Software Development Kit on this computer and click next. You will have to choose whether to allow insights for Windows SDK usage and must accept the license agreement before you arrive at the feature installation page. The only features you should install (unless you are using an Insider Preview build of Windows 10) are:<\/p>\n<ul>\n<li>Windows SDK Signing Tools for Desktop Apps<\/li>\n<li>Windows SDK for UWP Managed Apps<\/li>\n<li>Windows SDK for UWP C++ Apps<\/li>\n<li>Windows SDK for Desktop C++ x86 Apps (if planning on building for x86)<\/li>\n<li>Windows SDK for Desktop C++ amd64 Apps (if planning on building for amd64)<\/li>\n<li>Windows SDK for Desktop C++ arm Apps (if planning on building for arm)<\/li>\n<li>Windows SDK for Desktop C++ arm64 Apps (if planning on building for arm64)<\/li>\n<\/ul>\n<p><img decoding=\"async\" width=\"1099\" height=\"808\" class=\"wp-image-26570\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-6.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-6.png 1099w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-6-300x221.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-6-1024x753.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-6-768x565.png 768w\" sizes=\"(max-width: 1099px) 100vw, 1099px\" \/><\/p>\n<p>The SDK will take a couple minutes to complete installation and then you can open Visual Studio 16.8 Preview 3.<\/p>\n<h4>Step 4: Configuring C11 or C17 mode in Visual Studio 16.8 Preview 3<\/h4>\n<p>Support for C11 and C17 begins in Visual Studio 16.8 Preview 3. You can download the latest Preview via <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">https:\/\/visualstudio.microsoft.com\/vs\/preview\/<\/a>.<\/p>\n<p>In your project, open the Properties page. First, we want to ensure that the project will use the Insiders Preview Window 10 SDK. Set Windows SDK Version to 10.0.20206.0 (or the latest Insider Preview Windows 10 SDK just installed).<\/p>\n<p><img decoding=\"async\" width=\"1123\" height=\"777\" class=\"wp-image-26571\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-7.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-7.png 1123w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-7-300x208.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-7-1024x709.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-7-768x531.png 768w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/p>\n<p>You will also see a new option: C Language Standard. Set this to ISO C11 Standard (<code>\/std:c11<\/code>) or ISO C17 (2018) Standard (<code>\/std:c17<\/code>).<\/p>\n<p><img decoding=\"async\" width=\"1102\" height=\"759\" class=\"wp-image-26572\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-8.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-8.png 1102w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-8-300x207.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-8-1024x705.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-8-768x529.png 768w\" sizes=\"(max-width: 1102px) 100vw, 1102px\" \/><\/p>\n<p>The C++ Language Standard is used when the language is C++ &#8211; this will be the default when the file extension is <code>.cpp<\/code>. The C Language Standard version is used when the language is C \u2013 this will be the default when the file extension is <code>.c<\/code>. To ensure the project is building with C11 or C17, you must ensure it is a <code>.c<\/code> file, or set the code to compile as C in the Properties tab.<\/p>\n<p><img decoding=\"async\" width=\"1099\" height=\"762\" class=\"wp-image-26573\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-9.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-9.png 1099w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-9-300x208.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-9-1024x710.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/09\/word-image-9-768x532.png 768w\" sizes=\"(max-width: 1099px) 100vw, 1099px\" \/><\/p>\n<p>After these project changes, you\u2019re ready to test out C11 and C17!<\/p>\n<h3>In Conclusion<\/h3>\n<p>We are very excited to finally support C11 and C17! As the highest voted Developer Community suggestion, we\u2019re sure you\u2019re excited too. If you want support for the optional features of C11, please let us know on <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a>.<\/p>\n<p>As always, we welcome your feedback. We can be reached via the comments below or via email (visualcpp@microsoft.com). If you encounter problems with Visual Studio or MSVC, or have a suggestion for us, please let us know through Help &gt; Send Feedback &gt; Report A Problem \/ Provide a Suggestion in the product, or via <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a>. You can also find us on Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please see our Visual Studio 2019 version 16.8 Preview 3 release notes for more of our latest features. Update: Windows 10 SDK version 2104 has been released, which includes the changes needed for C11 and C17 as well as the conformant preprocessor. It can be downloaded here. To use this SDK, follow the instructions from [&hellip;]<\/p>\n","protected":false},"author":17039,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-26562","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>Please see our Visual Studio 2019 version 16.8 Preview 3 release notes for more of our latest features. Update: Windows 10 SDK version 2104 has been released, which includes the changes needed for C11 and C17 as well as the conformant preprocessor. It can be downloaded here. To use this SDK, follow the instructions from [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/26562","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\/17039"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=26562"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/26562\/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=26562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=26562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=26562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}