|
1 | 1 | --- |
2 | 2 | description: "Learn more about: /Zc:__cplusplus (Enable updated __cplusplus macro)" |
3 | 3 | title: "/Zc:__cplusplus (Enable updated __cplusplus macro)" |
4 | | -ms.date: "05/16/2019" |
| 4 | +ms.date: 08/11/2021 |
5 | 5 | f1_keywords: ["/Zc:__cplusplus"] |
6 | 6 | helpviewer_keywords: ["-Zc:__cplusplus compiler option (C++)", "__cplusplus macro (C++)"] |
7 | 7 | --- |
8 | | -# /Zc:__cplusplus (Enable updated __cplusplus macro) |
| 8 | +# `/Zc:__cplusplus` (Enable updated `__cplusplus` macro) |
9 | 9 |
|
10 | | -The **/Zc:__cplusplus** compiler option enables the **\_\_cplusplus** preprocessor macro to report an updated value for recent C++ language standards support. By default, Visual Studio always returns the value "199711L" for the **\_\_cplusplus** preprocessor macro. |
| 10 | +The **`/Zc:__cplusplus`** compiler option enables the `__cplusplus` preprocessor macro to report an updated value for recent C++ language standards support. By default, Visual Studio always returns the value `199711L` for the `__cplusplus` preprocessor macro. |
11 | 11 |
|
12 | 12 | ## Syntax |
13 | 13 |
|
14 | | -> **/Zc:__cplusplus**[**-**] |
| 14 | +> **`/Zc:__cplusplus`**[**`-`**] |
15 | 15 |
|
16 | 16 | ## Remarks |
17 | 17 |
|
18 | | -The **\_\_cplusplus** preprocessor macro is commonly used to report support for a particular version of the C++ standard. Because lots of existing code appears to depend on the value of this macro matching "199711L", the compiler does not change the value of the macro unless you explicitly opt-in by using the **/Zc:__cplusplus** compiler option. The **/Zc:__cplusplus** option is available starting in Visual Studio 2017 version 15.7, and is off by default. In earlier versions of Visual Studio, and by default, or if **/Zc:__cplusplus-** is specified, Visual Studio returns the value "199711L" for the **\_\_cplusplus** preprocessor macro. The [/permissive-](permissive-standards-conformance.md) option does not enable **/Zc:__cplusplus**. |
| 18 | +The `__cplusplus` preprocessor macro is commonly used to report support for a particular version of the C++ standard. Because a lot of existing code appears to depend on the value of this macro matching `199711L`, the compiler doesn't change the value of the macro unless you explicitly opt in by using the **`/Zc:__cplusplus`** compiler option. The **`/Zc:__cplusplus`** option is available starting in Visual Studio 2017 version 15.7, and is off by default. In earlier versions of Visual Studio, and by default, or if **`/Zc:__cplusplus-`** is specified, Visual Studio returns the value `199711L` for the `__cplusplus` preprocessor macro. The [`/permissive-`](permissive-standards-conformance.md) option doesn't enable **`/Zc:__cplusplus`**. |
19 | 19 |
|
20 | | -When the **/Zc:__cplusplus** option is enabled, the value reported by the **\_\_cplusplus** macro depends on the [/std](std-specify-language-standard-version.md) version switch setting. This table shows the possible values for the macro: |
| 20 | +When the **`/Zc:__cplusplus`** option is enabled, the value reported by the `__cplusplus` macro depends on the [`/std`](std-specify-language-standard-version.md) version option setting. This table shows the possible values for the macro: |
21 | 21 |
|
22 | | -|/Zc:__cplusplus switch|/std:c++ switch|__cplusplus value| |
23 | | -|-|-|-| |
24 | | -Zc:__cplusplus|/std:c++14 (default)|201402L |
25 | | -Zc:__cplusplus|/std:c++17|201703L |
26 | | -Zc:__cplusplus|/std:c++latest|201704L |
27 | | -Zc:__cplusplus- (disabled)|Any value|199711L |
28 | | -Not specified|Any value|199711L |
| 22 | +| `/Zc:__cplusplus` option | `/std` option | `__cplusplus` value | |
| 23 | +|--|--|--| |
| 24 | +| `Zc:__cplusplus` | `/std:c++14` (default) | `201402L` | |
| 25 | +| `Zc:__cplusplus` | `/std:c++17` | `201703L` | |
| 26 | +| `Zc:__cplusplus` | `/std:c++20` | `202002L` | |
| 27 | +| `Zc:__cplusplus` | `/std:c++latest` | see text | |
| 28 | +| `Zc:__cplusplus-` (disabled) | Any value | `199711L` | |
| 29 | +| Not specified | Any value | `199711L` | |
29 | 30 |
|
30 | | -The compiler does not support standards switches for C++98, C++03, or C++11. |
| 31 | +The compiler doesn't support standards options for C++98, C++03, or C++11. The **`/std:c++20`** option is available starting in Visual Studio 2019 version 16.11. The value of `__cplusplus` with the **`/std:c++latest`** option depends on the version of Visual Studio. It's always at least one higher than the highest supported `__cplusplus` standard value supported by your version of Visual Studio. |
31 | 32 |
|
32 | | -For finer-grained detection of changes to the compiler toolset, use the [_MSC_VER](../../preprocessor/predefined-macros.md) predefined macro. The value of this built-in macro is incremented for every toolset update in Visual Studio 2017 and later versions. The [_MSVC_LANG](../../preprocessor/predefined-macros.md) predefined macro reports the standard version whether the **/Zc:__cplusplus** option is enabled or disabled. When **/Zc:__cplusplus** is enabled, `__cplusplus == _MSVC_LANG`. |
| 33 | +For finer-grained detection of changes to the compiler toolset, use the [`_MSC_VER`](../../preprocessor/predefined-macros.md) predefined macro. The value of this built-in macro is incremented for every toolset update in Visual Studio 2017 and later versions. The [`_MSVC_LANG`](../../preprocessor/predefined-macros.md) predefined macro reports the standard version whether the **`/Zc:__cplusplus`** option is enabled or disabled. When **`/Zc:__cplusplus`** is enabled, `__cplusplus` has the same value as `_MSVC_LANG`. |
33 | 34 |
|
34 | 35 | ### To set this compiler option in Visual Studio |
35 | 36 |
|
36 | 37 | 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). |
37 | 38 |
|
38 | 39 | 1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page. |
39 | 40 |
|
40 | | -1. Add **/Zc:__cplusplus** or **/Zc:__cplusplus-** to the **Additional options:** pane. |
| 41 | +1. Add **`/Zc:__cplusplus`** or **`/Zc:__cplusplus-`** to the **Additional options:** pane. |
41 | 42 |
|
42 | 43 | ## See also |
43 | 44 |
|
44 | | -- [/Zc (Conformance)](zc-conformance.md) |
45 | | -- [/std (Specify language standard version)](std-specify-language-standard-version.md) |
46 | | -- [Predefined macros](../../preprocessor/predefined-macros.md) |
| 45 | +[`/Zc` (Conformance)](zc-conformance.md)\ |
| 46 | +[`/std` (Specify language standard version)](std-specify-language-standard-version.md)\ |
| 47 | +[Predefined macros](../../preprocessor/predefined-macros.md) |
0 commit comments