enum protocol {
ascii_prot = 3, /* arbitrary value. */
binary_prot,
negotiating_prot = 4 /* Discovering the protocol */
};
binary_prot
和negotiating_prot
等于4
?在C中有重复的枚举值是合法的吗?
enum protocol {
ascii_prot = 3, /* arbitrary value. */
binary_prot,
negotiating_prot = 4 /* Discovering the protocol */
};
binary_prot
和negotiating_prot
等于4
?在C中有重复的枚举值是合法的吗?
是; C不是关于枚举值的。为什么你可能会这样做是另一个问题,除非有理由将发现数据包与数据包一样对待。 (其他人设计协议时可能会出现这种情况,并且您希望尽可能贴近他们的文档。)
它被** [N1265 C99草案](http:// www在6.7.2.2/3“Enumeration specifiers”中使用“.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf”:“使用带有'='的枚举器可能产生枚举常量,值在同一个枚举中。“。我已经把这个答案,但http://stackoverflow.com/users/100297删除它,因为重复的答案:http://stackoverflow.com/a/30916409/895245我不认为这些问题是重复的。 – 2015-06-18 17:25:55