gpt4 book ai didi

c - 在 [C] 中将 `enum` 转换为其他 `enum` 是否有效?

转载 作者:太空狗 更新时间:2023-10-29 17:11:32 25 4
gpt4 key购买 nike

我有两个枚举。

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).

关于c - 在 [C] 中将 `enum` 转换为其他 `enum` 是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com