c++ - 在 C 中允许重复的 const 限定符但在 C++ 中不允许?

标签 c++ c language-agnostic constants

示例代码片段

const const const int x = 10;   
int main()
{}

在 C 中编译,但在 C++ 中不编译。为什么要用 C 编译?我认为这在 C 中也会失败。没关系。

C++ 标准的哪一部分禁止使用重复的const,C 标准的哪一部分允许这样做?

最佳答案

C99 §6.7.3/4:

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,您的发现是正确的。

关于c++ - 在 C 中允许重复的 const 限定符但在 C++ 中不允许?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58634707/

相关文章:

C++ zlib 压缩文件中的字符串

c - 它是链表实现吗?

c - c中的 union 初始化

c - 高效的 4x4 矩阵乘法(C 语言与汇编语言)

language-agnostic - 常见的伪代码问题、谜题和挑战

algorithm - 找到最大簇的最小值?

c++ - 链接 CMakeLists : ld cannot find library

c++ - 如何接受后缀和中缀表示法中的负值?

algorithm - 三角划分

c++ - Linux 的 Qt 应用程序部署