我认为这是C 11标准中的(次要)缺陷

前端之家收集整理的这篇文章主要介绍了我认为这是C 11标准中的(次要)缺陷前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我认为这是C 11标准中的(次要)缺陷.在[dcl.dcl]中我们有:

simple-declaration:

decl-specifier-seqopt init-declarator-listopt ;

decl-specifier-seq不能是可选的.

例如,下面的代码片段无法编译:

x;

如果我在这里是正确的,那么第8.3 / 1段的开头也应该改变:

从:

A list of declarators appears after an optional (Clause 7)
decl-specifier-seq (7.1).

至:

A list of declarators appears after a decl-specifier-seq (7.1).

解决方法

评论太久了

在第7条第3款中:

In a simple-declaration,the optional init-declarator-list can be
omitted only when declaring a class (Clause 9) or enumeration (7.2),
that is,when the decl-specifier-seq contains either a
class-specifier,an elaborated-type-specifier with a class-key (9.1),
or an enum-specifier.
In these cases and whenever a class-specifier or
enum-specifier is present in the decl-specifier-seq,the identifiers
in these specifiers are among the names being declared by the
declaration (as class-names,enum-names,or enumerators,depending on
the Syntax). In such cases,and except for the declaration of an
unnamed bit-field (9.6),the decl-specifier-seq shall introduce one or
more names into the program,or shall redeclare a name introduced by a
prevIoUs declaration.

并在第7条第9款中

Only in function declarations for constructors,destructors,and type
conversions can the decl-specifier-seq be omitted.

猜你在找的C&C++相关文章