|
1 | 1 | --- |
2 | 2 | title: "/std (Specify Language Standard Version)" |
3 | | -ms.date: "06/04/2020" |
4 | | -f1_keywords: ["/std", "-std", "VC.Project.VCCLCompilerTool.CppLanguageStandard"] |
| 3 | +description: "The MSVC compiler option /std specifies the C or C++ language standard supported by the compiler." |
| 4 | +ms.date: 09/11/2020 |
| 5 | +f1_keywords: ["/std", "-std", "/std:c++14", "/std:c++17", "/std:c11", "/std:c17", "VC.Project.VCCLCompilerTool.CppLanguageStandard"] |
5 | 6 | ms.assetid: 0acb74ba-1aa8-4c05-b96c-682988dc19bd |
6 | 7 | --- |
7 | 8 | # `/std` (Specify Language Standard Version) |
8 | 9 |
|
9 | | -Enable supported C++ language features from the specified version of the C++ language standard. |
| 10 | +Enable supported C and C++ language features from the specified version of the C or C++ language standard. |
10 | 11 |
|
11 | 12 | ## Syntax |
12 | 13 |
|
13 | 14 | > **`/std:c++14`**\ |
14 | 15 | > **`/std:c++17`**\ |
15 | | -> **`/std:c++latest`** |
| 16 | +> **`/std:c++latest`**\ |
| 17 | +> **`/std:c11`**\ |
| 18 | +> **`/std:c17`** |
16 | 19 |
|
17 | 20 | ## Remarks |
18 | 21 |
|
19 | | -The **`/std`** option is available in Visual Studio 2017 and later. It's used to control the version-specific ISO C++ programming language standard features enabled during compilation of your code. This option allows you to disable support for certain new language and library features: ones that may break your existing code that conforms to a particular version of the language standard. By default, **`/std:c++14`** is specified, which disables language and standard library features found in later versions of the C++ language standard. Use **`/std:c++17`** to enable C++17 standard-specific features and behavior. To explicitly enable the currently implemented compiler and standard library features proposed for the next draft standard, use **`/std:c++latest`**. All C++20 features require **`/std:c++latest`**; when the implementation is complete, a new **`/std:c++20`** option will be enabled. |
| 22 | +The **`/std`** option is available in Visual Studio 2017 and later. It's used to control the version-specific ISO C or C++ programming language standard features enabled during compilation of your code. This option allows you to disable support for certain new language and library features: ones that may break your existing code that conforms to a particular version of the language standard. |
| 23 | + |
| 24 | +### C++ standards support |
| 25 | + |
| 26 | +By default, **`/std:c++14`** is specified, which disables language and standard library features found in later versions of the C++ language standard. Use **`/std:c++17`** to enable C++17 standard-specific features and behavior. To explicitly enable the currently implemented compiler and standard library features proposed for the next draft standard, use **`/std:c++latest`**. All C++20 features require **`/std:c++latest`**; when the implementation is complete, a new **`/std:c++20`** option will be enabled. |
20 | 27 |
|
21 | 28 | The default **`/std:c++14`** option enables the set of C++14 features implemented by the MSVC compiler. This option disables compiler and standard library support for features that are changed or new in more recent versions of the language standard. It doesn't disable some C++17 features already implemented in previous releases of the MSVC compiler. To avoid breaking changes for users who have already taken dependencies on the features available in or before Visual Studio 2015 Update 2, these features remain enabled when the **`/std:c++14`** option is specified: |
22 | 29 |
|
@@ -46,13 +53,50 @@ The **`/std:c++14`** and **`/std:c++latest`** options are available beginning in |
46 | 53 | > [!NOTE] |
47 | 54 | > Depending on the MSVC compiler version or update level, C++17 features may not be fully implemented or fully conforming when you specify the **`/std:c++17`** options. For an overview of C++ language conformance in Visual C++ by release version, see [Microsoft C++ language conformance table](../../overview/visual-cpp-language-conformance.md). |
48 | 55 |
|
| 56 | +### C standards support |
| 57 | + |
| 58 | +By default, when code is compiled as C, the MSVC compiler doesn't conform to a particular C standard. It implements ANSI C89 with several Microsoft extensions, some of which are part of ISO C99. Some Microsoft extensions can be disabled by using the [`/Za`](za-ze-disable-language-extensions.md) compiler option, but others remain in effect. It isn't possible to specify strict C89 conformance. |
| 59 | + |
| 60 | +Starting in Visual Studio 2019 version 16.8, you may specify **`/std:c11`** or **`/std:c17`** for code compiled as C. These options specify conformance modes that correspond with ISO C11 and ISO C17. Because the new preprocessor is needed to support these standards, the **`/std:c11`** and **`/std:c17`** compiler options set the [`/Zc:preprocessor`](zc-preprocessor.md) option automatically. If you want to use the traditional (legacy) preprocessor for C11 or C17, you must set the **`/Zc:preprocessor-`** compiler option explicitly. Setting the **`/Zc:preprocessor-`** option may lead to unexpected behavior, and isn't recommended. |
| 61 | + |
| 62 | +> [!NOTE] |
| 63 | +> At the time of release, the latest Windows SDK and UCRT libraries do not yet support C11 and C17 code. A pre-release version of the Windows SDK and UCRT is required. For more information and installation instructions, see [Install C11 and C17 support in Visual Studio](../../overview/install-c17-support.md). |
| 64 | +
|
| 65 | +When you specify **`/std:c11`** or **`/std:c17`**, MSVC supports all the required features of C11 and C17. The compiler options enable support for these functionalities: |
| 66 | + |
| 67 | +- **`_Pragma`** |
| 68 | + |
| 69 | +- **`restrict`** |
| 70 | + |
| 71 | +- **`_Noreturn`** and \<stdnoreturn.h> |
| 72 | + |
| 73 | +- **`_Alignas`**, **`_Alignof`** and \<stdalign.h> |
| 74 | + |
| 75 | +- **`_Generic`** and \<tgmath.h> |
| 76 | + |
| 77 | +- **`_Static_assert`** |
| 78 | + |
| 79 | +The IDE uses C settings for IntelliSense and code highlighting when your source files have a *`.c`* file extension, or when you specify the [`/TC`](tc-tp-tc-tp-specify-source-file-type.md) compiler option. Currently, IntelliSense highlighting is only available for keywords, and not the macros introduced by the standard headers. |
| 80 | + |
| 81 | +Since C17 is largely a bug fix release of ISO C11, MSVC 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 `__STDC_VERSION__` macro. It expands to `201112L` for C11, and `201710L` for C17. |
| 82 | + |
| 83 | +The compiler doesn't support any optional features of ISO C11. Several of these optional features of C11 were required features of C99 that MSVC hasn't implemented for architectural reasons. You can use the feature test macros such as `__STDC_NO_VLA__` to detect compiler support levels for individual features. For more information about C-specific predefined macros, see [Predefined macros](../../preprocessor/predefined-macros.md). |
| 84 | + |
| 85 | +- There's no conforming multithreading, atomic, or complex number support in the Visual Studio 2019 version 16.8 release. |
| 86 | + |
| 87 | +- `aligned_alloc` support is missing, because of the Windows heap implementation. The alternative is to use [`_aligned_malloc`](../../c-runtime-library/reference/aligned-malloc.md). |
| 88 | + |
| 89 | +- DR 400 support is currently unimplemented for `realloc`, because this change would break the ABI. |
| 90 | + |
| 91 | +- Variable length array (VLA) support isn't planned. Variable length arrays are often less efficient than comparable fixed sized arrays. They're also inefficient compared to equivalent heap memory allocations, when safely and securely implemented. VLAs provide attack vectors comparable to `gets()`, which is deprecated and planned for removal. |
| 92 | + |
49 | 93 | ### To set this compiler option in the Visual Studio development environment |
50 | 94 |
|
51 | 95 | 1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md). |
52 | 96 |
|
53 | 97 | 1. Select **Configuration Properties**, **C/C++**, **Language**. |
54 | 98 |
|
55 | | -1. In **C++ Language Standard**, choose the language standard to support from the dropdown control, then choose **OK** or **Apply** to save your changes. |
| 99 | +1. In **C++ Language Standard** (or for C, **C Language Standard**), choose the language standard to support from the dropdown control, then choose **OK** or **Apply** to save your changes. |
56 | 100 |
|
57 | 101 | ## See also |
58 | 102 |
|
|
0 commit comments