Is it legal to have duplicate enum values in C?

后端 未结 2 852
梦毁少年i
梦毁少年i 2021-01-07 18:22
enum protocol {
    ascii_prot = 3, /* arbitrary value. */
    binary_prot,
    negotiating_prot = 4 /* Discovering the protocol */
};

Both b

2条回答
  •  滥情空心
    2021-01-07 19:04

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

提交回复
热议问题