Is it legal to have duplicate enum values in C?

后端 未结 2 828
梦毁少年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.)

    0 讨论(0)
  • 2021-01-07 19:16

    Yes.

    0 讨论(0)
提交回复
热议问题