Why is #define bad and what is the proper substitute?

后端 未结 6 1141
情深已故
情深已故 2020-11-30 12:37
#define dItemName        L\"CellPhone\"
6条回答
  •  暖寄归人
    2020-11-30 13:24

    Because preprocessor macros, which you've just made, pollute every name scope. They are available everywhere and do not follow standard naming scope rules. Thus, with a macro like that, code like int dItemName = 5; instead gets f'ed over by the preprocessor to instead be int L"CellPhone" = 5;. A constant, global variable would not do this.

    All other issues aside, this is IMNSHO the worse issue with macro definitions.

提交回复
热议问题