What are the major advantages of const versus #define for global constants?

前端 未结 7 1127
北恋
北恋 2021-01-14 10:28

In embedded programming, for example, #define GLOBAL_CONSTANT 42 is preferred to const int GLOBAL_CONSTANT = 42; for the following reasons:

相关标签:
7条回答
  • 2021-01-14 11:13

    The only problems you list with const sum up as "I've got the most incompetent compiler I can possibly imagine". The problems with #define, however, are universal- for example, no scoping.

    0 讨论(0)
提交回复
热议问题