重复的const修饰词允许在C,但不是在C ++? [英] Duplicate const qualifier allowed in C but not in C++?

查看:175
本文介绍了重复的const修饰词允许在C,但不是在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样code段

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 ++标准的一部分,禁止使用重复的常量和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:

如果同样的预选赛出现在同一的符限定符列表不止一次的,直接或通过一个或多个的typedef S,行为是一样的如果只出现过一次。

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.

这篇关于重复的const修饰词允许在C,但不是在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆