What is the value of __cplusplus for C++17?(__cplusplus 对于 C++17 的值是多少?)
问题描述
我们正在尝试在 C++17 及其 更改为 std::uncaught_exception 下测试一些代码.我似乎无法让 GCC 提供 __cplusplus 的值:
$/opt/local/bin/g++ -std=c++17 -dM -E - </dev/null |grep __cpluspluscc1:警告:命令行选项-std=c++1z"对 C++/ObjC++ 有效,但对 C 无效$还有:
$/opt/local/bin/g++ --versiong++-mp-6 (MacPorts gcc6 6.1.0_0) 6.1.0版权所有 (C) 2016 Free Software Foundation, Inc.使用C++17时__cplusplus的值是多少?
tl;dr: 对于 C++17,__cplusplus 是 201703L.
<块引用>使用C++17时__cplusplus的值是多少?
根据标准草案N4594§16.8/p1 预定义的宏名称 [cpp.predefined](Emphasis Mine):
<块引用>以下宏名称应由实现定义:__cplusplus 名称 __cplusplus 定义为值201402L 编译 C++ 翻译单元时.156
156) 本标准的未来版本旨在用更大的值替换这个宏的值.不合格编译器应该使用最多五个十进制数字的值.
但是,为 C++14 标准指定了相同的值.显然,目前还没有为 C++17 标准设置官方/标准 __cplusplus 值.
在 GCC 版本 6.1 和 7.0 中,该值更改为 201500
现场演示
在 Clang 版本 3.8 和 3.9 中,该值保持不变201406.
因此,您必须稍等片刻才能得出标准值.
--- 更新---
根据 C++ 标准§19.8/p1 预定义的宏名称 [cpp.predefined](Emphasis Mine):
<块引用>1 以下宏名称应由实现:
__cplusplus 整数字面量201703L.
因此,使用C++17时__cplusplus的值为201703L.
We are trying to test some code under C++17 and its change to std::uncaught_exception. I can't seem to get GCC to provide the value of __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
$
And:
$ /opt/local/bin/g++ --version
g++-mp-6 (MacPorts gcc6 6.1.0_0) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
What is the value of __cplusplus when using C++17?
tl;dr: For C++17, __cplusplus is 201703L.
What is the value of
__cpluspluswhen using C++17?
According to the draft standard N4594 §16.8/p1 Predefined macro names [cpp.predefined] (Emphasis Mine):
The following macro names shall be defined by the implementation:
__cplusplusThe name__cplusplusis defined to the value 201402L when compiling a C++ translation unit.156156) 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.
However the same value is appointed for the C++14 standard. Apparently it seems so, that there's no official/standard __cplusplus value set yet for the C++17 standard.
In GCC versions 6.1 and 7.0 the value is changed to 201500
Live Demo
In Clang version 3.8 and 3.9 the value is unchanged 201406.
Consequently, you'll have to wait a little bit for the standard value to come out.
--- Update ---
According to the C++ standard §19.8/p1 Predefined macro names [cpp.predefined] (Emphasis Mine):
1 The following macro names shall be defined by the implementation:
__cplusplusThe integer literal 201703L.
Thus, the value of __cplusplus when using C++17 shall be 201703L.
这篇关于__cplusplus 对于 C++17 的值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:__cplusplus 对于 C++17 的值是多少?
基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
