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