是否有效的“枚举”到[C]中的其他“枚举”?

前端之家收集整理的这篇文章主要介绍了是否有效的“枚举”到[C]中的其他“枚举”?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个枚举.
enum A { A1=1,A2=2 }

enum B { B1=1,B2=2 }

这是否符合C的标准?

A a = A1;
B b = a;

(与Clang编译得很好,但我不能确定这是标准还是扩展行为)

解决方法

它符合标准,但C99规范提到某些实现可能会生成警告:

An implementation may generate warnings in many situations,none of which are specified as part of this International Standard. The following are a few of the more common situations.

  • A value is given to an object of an enumerated type other than by assignment of an enumeration constant that is a member of that type,or an enumeration variable that has the same type,or the value of a function that returns the same enumerated type (6.7.2.2).
原文链接:https://www.f2er.com/c/118779.html

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