Official announcement: MSVC newly added C11 and C17 standards

Official announcement

We are pleased to announce that starting from Visual Studio 2019 v16.8 Preview 3, the two C language versions, C11 and C17, will be added to the MSVC compiler toolset.
For many years, Visual Studio has limited support for C only because of the needs of C++. Now, things have changed: we have added a token-based normalization preprocessor to the compiler. With the help of two newly added compiler switches: /std:c11 and /std:c17, we can finally officially announce Visual Studio can support the latest version of the C language standard.

What are the specific things?

All features in C11 and C17 will be supported. This means that we will add the following functions:
> _Pragma
> restrict
> _Noreturn and
> _Alignas, _Alignof and
> _Generic and support
> _Static_assert

The IntelliSense component will seamlessly integrate with these features. You only need to name your source code file with the end of .c, or use the compiler switch /TC to enable syntax highlighting, as shown in the following figure:

 

Currently IntelliSense only supports the highlighting of keywords, and cannot handle macros in standard header files. This problem will be fixed in a later version.

Because C17 is essentially just a bug fix to ISO C, it also adds a lot of bug report processing. Our support for C11 already includes these related defect handling. Except for the definition of the __STDC_VERSION__ macro, there is basically no difference between our support for C11 and C17. In C11, __STDC_VERSION__ is defined as 201112L, and in C17 it is defined as 201710L.
The following is a simple example, which demonstrates some of the features mentioned above:

 

 

Because of the introduction of the Token-based canonical preprocessor, the two C compiler switches mentioned above implicitly include the /Zc:preprocessor option. If you still want to use the traditional, character-based preprocessor, you can use the /Zc:preprocessor- switch to return to the old mode. But we encourage you to modify the code as much as possible to make it no longer dependent on the old working model.

Features not yet supported

Currently does not support any of the optional features in C11, but we will still provide those influential optional features in a future version. In our roadmap, Atomic and Threading are already on the agenda. Complex numbers are not currently supported, but they can be simulated by some suitable test macros. You can tell us which features you want, so we can prioritize them.
Due to some features of the Windows heap, aligned_alloc is not yet supported. As an alternative, you can use _aligned_malloc.
In addition, DR 400 support for realloc has not yet been implemented in the current version, because this may break the ABI.

Variable-length array

VLA (Variable Length Arrays) is an optional feature in C11, and careful readers may have noticed: VLA is also not supported. In terms of performance, VLA is not as good as a fixed-length array, and when security checks are enabled, VLA is not as good as malloc(). At the same time, VLA also provides potential attackers with "Shifting the stack" vulnerability exploit opportunities and other security risks. For these reasons, we decided to not support the VLA feature for the time being.

Getting started with C11 and C17

In order to use C11 or C17 in your program, you may need to install the latest version of the Windows SDK. The SDK contains the required preprocessor (/Zc:preprocessor) and a new universal C runtime library.
Generally speaking, the Windows SDK is released together with the Windows system. Because the official version of Windows does not include these new features, you need to download the preview version of the Windows SDK (for the Windows SDK preview version provided to Windows Insider).
Please note that when the preview SDK is installed, projects configured to use the latest version of the Windows SDK in Visual Studio will use the installed preview SDK.

Step 1: The entrance
to the preview SDK The following figure is the entrance to the preview SDK download:

 

 

 

Step 2: Download the preview SDK

 

 

Step 3: Install the preview SDK

 

 

 

 Step 4: Configure C11 or C17 working mode in Visual Studio v16.8 Preview 3

First open the project properties, and then make sure that the SDK used by the project is the preview SDK. As shown in the figure below, set the Windows SDK version to 10.0.20206.0 (or set the latest installed version)

 

In C Language Standard, it can be set to C11 or C17 according to the needs of the project.

 

In order to ensure that the code is compiled with C11 or C17, please name the source file to end with .c, or set the following compilation options for compilation:

 

Congratulations: After these steps, you can experience C11 and C17.

At last

The blog of the Microsoft Visual C++ team is one of my favorite blogs. It contains a lot of knowledge about Visual C++ and the latest developments. If you are still interested in the ancient technology of Visual C++, you can often visit them (or me).
This article comes from: "C11 and C17 Standard Support Arriving in MSVC"

Guess you like

Origin blog.csdn.net/mmxida/article/details/108630002