gpt4 book ai didi

c++ - __cplusplus 对于 C++17 的值是多少?

转载 作者:IT老高 更新时间:2023-10-28 12:50:15 30 4
gpt4 key购买 nike

我们正在尝试在 C++17 及其 change to std::uncaught_exception 下测试一些代码。 .我似乎无法让 GCC 提供 __cplusplus 的值:

$ /opt/local/bin/g++ -std=c++17 -dM -E - </dev/null | grep __cplusplus
cc1: warning: command line option '-std=c++1z' is valid for C++/ObjC++ but not for C
$

还有:

$ /opt/local/bin/g++ --version
g++-mp-6 (MacPorts gcc6 6.1.0_0) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.

使用C++17时__cplusplus的值是多少?

最佳答案

tl;dr:对于 C++17,__cplusplus201703L

What is the value of __cplusplus when using C++17?

根据标准草案N4594 §16.8/p1 预定义的宏名称 [cpp.predefined](Emphasis Mine):

The following macro names shall be defined by the implementation:__cplusplus The name __cplusplus is defined to the value201402L when compiling a C++ translation unit.156

156) It is intended that future versions of this standard willreplace the value of this macro with a greater value. Non-conformingcompilers should use a value with at most five decimal digits.

但是,为 C++14 标准指定了相同的值。显然,目前还没有为 C++17 标准设置官方/标准 __cplusplus 值。

在 GCC 版本 6.1 和 7.0 中,该值更改为 201500

Live Demo

在 Clang 版本 3.8 和 3.9 中,该值保持不变201406

因此,您必须稍等片刻才能得出标准值。

--- 更新---

根据 C++ 标准§19.8/p1 预定义的宏名称 [cpp.predefined](Emphasis Mine):

1 The following macro names shall be defined by theimplementation:

__cplusplus The integer literal 201703L.

因此,使用C++17时__cplusplus的值为201703L

关于c++ - __cplusplus 对于 C++17 的值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38456127/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com