枚举{A,B,}

编程入门 行业动态 更新时间:2024-10-16 00:21:25
本文介绍了枚举{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,}

本文发布于:2023-11-30 03:51:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!