Duplicate const qualifier allowed in C but not in C++?

前端 未结 4 452
不知归路
不知归路 2020-12-03 13:35

Sample code snippet

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

gets compiled in C but not in C++. Why does it get compiled in C? I thou

4条回答
  •  天涯浪人
    2020-12-03 14:14

    From the last C++0x draft, [dcl.type]:

    As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration or in a type-specifier-seq or trailing-type-specifier-seq. The only exceptions to this rule are the following:

    — const can be combined with any type specifier except itself.

    — volatile can be combined with any type specifier except itself.

    — signed or unsigned can be combined with char, long, short, or int.

    — short or long can be combined with int.

    — long can be combined with double.

    — long can be combined with long.

提交回复
热议问题