对于C 17,__cplusplus的值是多少?

前端之家收集整理的这篇文章主要介绍了对于C 17,__cplusplus的值是多少?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们试图在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的值是多少?

解决方法

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 value
201402L when compiling a C++ translation unit.156

@H_301_36@156) It is intended that future versions of this standard will
replace the value of this macro with a greater value. Non-conforming
compilers should use a value with at most five decimal digits.

然而,对于C14标准指定的价值相同.显然,似乎这样,没有为C 17标准设定的官方/标准__cplusplus值.

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

Live Demo

在Clang版本3.8和3.9中,值不变201406.

因此,您必须稍等一点才能出现标准值.

原文链接:https://www.f2er.com/c/110475.html

猜你在找的C&C++相关文章