我有两个枚举.
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).