枚举{A,B,} [英] enum { A,B, }
问题描述
您好。我注意到我的编译器接受了
enum
{
A,// comment
B ,//注释
};
注意B之后的逗号。
这是合法的ANSI C和C ++标准?
Hi. I notice that my compiler accepts
enum
{
A, // comment
B, // comment
};
Notice the trailing comma after B.
Is this legal per the ANSI C and C++ standards?
推荐答案
不,它是您的编译器提供的非标准扩展。根据§7.2.1(未明确,但它列出了唯一的
允许的枚举声明形式)ISO / IEC
非法
C ++ - 2003标准。
No, it is a non-standard extension provided by your compiler. It is
illegal according to §7.2.1 (not explicitly, but it lists the only
acceptable forms of enumeration declaration allowed) of the ISO/IEC
C++-2003 standard.
Siemel Naran写道:
Siemel Naran wrote:
嗨。我注意到我的编译器接受了
enum
{
A,//评论
B,//评论
};
这是否符合ANSI C和C ++标准?
...
Hi. I notice that my compiler accepts
enum
{
A, // comment
B, // comment
};
Notice the trailing comma after B.
Is this legal per the ANSI C and C++ standards?
...
它在C99中是合法的,但在C89 / 90和C ++中是非法的。
请注意,在聚合初始值设定项中,尾随逗号在C中是合法的并且
C ++
int a [] = {1,2,3,};
C99简单地同步这两个语法相似的语法
结构。许多编译器都这样做,即使在C ++代码中也允许枚举额外的逗号
定义。
-
祝你好运,
Andrey Tarasevich
It is legal in C99, but illegal in C89/90 and C++.
Note that in aggregate initializers the trailing comma is legal in C and
C++
int a[] = { 1, 2, 3, };
C99 simply "synchronized" the syntax of these two syntactically similar
constructs. Many compilers do the same, allowing the extra comma in enum
definitions even in C++ code.
--
Best regards,
Andrey Tarasevich
它适用于我的gcc 2.95 c ++编译器。
It works in my gcc 2.95 c++ compiler.
>
这篇关于枚举{A,B,}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!