Typesafe enums in C?

后端 未结 6 612
我寻月下人不归
我寻月下人不归 2021-01-12 02:29

If I have more than one enum, eg:

 enum Greetings{ hello, bye, how };

 enum Testing { one, two, three };

How can I enforce th

6条回答
  •  [愿得一人]
    2021-01-12 02:35

    This is the answer you don't want to hear. In C, you can't really. Now if your C code were in the "Clean C" subset of C++, you could compile with the C++ compiler to get all the errors of using the wrong enum/int values, etc.

提交回复
热议问题