“static const” vs “#define” vs “enum”

后端 未结 17 1930
一生所求
一生所求 2020-11-21 05:45

Which one is better to use among the below statements in C?

static const int var = 5;

or

#define var 5

o

17条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 06:06

    We looked at the produced assembler code on the MBF16X... Both variants result in the same code for arithmetic operations (ADD Immediate, for example).

    So const int is preferred for the type check while #define is old style. Maybe it is compiler-specific. So check your produced assembler code.

提交回复
热议问题