C 中重复的枚举值合法吗?
enum protocol {
ascii_prot = 3, /* arbitrary value. */
binary_prot,
negotiating_prot = 4 /* Discovering the protocol */
};
binary_prot
和 negotiating_prot
都等于 4
?
enum protocol {
ascii_prot = 3, /* arbitrary value. */
binary_prot,
negotiating_prot = 4 /* Discovering the protocol */
};
Both binary_prot
and negotiating_prot
equals to 4
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。
Yes.
是的; C 并不特别关注枚举值。为什么要这样做是另一个问题,除非有某种原因将发现数据包与数据包视为相同。 (当其他人设计协议并且您希望尽可能严格遵守他们的文档时,很可能会出现这种情况。)
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.)