Difference between Enum and Define Statements

后端 未结 18 2562
终归单人心
终归单人心 2020-11-30 00:27

What\'s the difference between using a define statement and an enum statement in C/C++ (and is there any difference when using them with either C or C++)?

For exampl

18条回答
  •  悲&欢浪女
    2020-11-30 00:59

    #define statements are handled by the pre-processor before the compiler gets to see the code so it's basically a text substitution (it's actually a little more intelligent with the use of parameters and such).

    Enumerations are part of the C language itself and have the following advantages.

    1/ They may have type and the compiler can type-check them.

    2/ Since they are available to the compiler, symbol information on them can be passed through to the debugger, making debugging easier.

提交回复
热议问题