Some good example for using enums

后端 未结 10 1593
感情败类
感情败类 2021-01-05 06:28

I learned enums when I learned C and from time to time I keep myself reminding about it and most of the time by re-reading from some source,it occurred to me that this is d

10条回答
  •  情歌与酒
    2021-01-05 07:16

    Enums have one advantage over #define, but it's purely an implementation detail: debuggers typically can show/use enum values but #defined values.

    On the other hand, #define has several fundamental advantages, one of which is that you can test for the existence with #ifdef. This is useful if you need to support multiple versions of a library, and want to optionally use new enum-like choices if they're available.

    Some library authors use a hybrid approach of first defining the constants with enum then:

    #define FOO FOO
    #define BAR BAR
    

    etc.

提交回复
热议问题