Duplicate const qualifier allowed in C but not in C++?(在 C 中允许重复的 const 限定符但在 C++ 中不允许?)
问题描述
示例代码片段
const const const int x = 10;
int main()
{}
在 C 中编译,但不在 C++ 中.为什么它会在 C 中编译?我认为这在 C 中也会失败.没关系.
gets compiled in C but not in C++. Why does it get compiled in C? I thought this would fail in C as well. Never mind.
C++ 标准的哪一部分禁止使用重复的 const
,而 C 标准的哪一部分允许这样做?
Which part of the C++ Standard forbids the use of duplicate const
and which part of the C standard allows this?
推荐答案
C99 §6.7.3/4:
C99 §6.7.3/4:
如果同一个限定符在同一个 specifier-qualifier-list 中出现多次,无论是直接出现还是通过一个或多个 typedef 出现,行为与如果它只出现一次.
If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedef s, the behavior is the same as if it appeared only once.
是的,那是有效的 C99,你的发现是正确的.
Yes, that is valid C99, and your discovery is correct.
这篇关于在 C 中允许重复的 const 限定符但在 C++ 中不允许?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C 中允许重复的 const 限定符但在 C++ 中不允许?


基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01