开发者

Is it legal to have duplicate enum values in C?

开发者 https://www.devze.com 2023-02-22 03:24 出处:网络
enum protocol { ascii_prot = 3, /* arbitrary value. */ binary_pro开发者_StackOverflow中文版t, negotiating_prot = 4 /* Discovering the protocol */
enum protocol {
    ascii_prot = 3, /* arbitrary value. */
    binary_pro开发者_StackOverflow中文版t,
    negotiating_prot = 4 /* Discovering the protocol */
};

Both binary_prot and negotiating_prot equals to 4?


Yes.


Yes; C is not particular about enum values. Why you might do that is another question, unless there's some reason to treat the discovery packet the same as data packets. (Which there might well be when someone else designed the protocol and you want to stick as closely as possible to their documentation.)

0

精彩评论

暂无评论...
验证码 换一张
取 消