Is #if defined MACRO equivalent to #ifdef MACRO?

后端 未结 5 1162
自闭症患者
自闭症患者 2020-12-08 21:38

I have code that I want to have two modes, debug and verbose. I define them in my header file as,

#define verbose TRUE
#def         


        
5条回答
  •  盖世英雄少女心
    2020-12-08 21:56

    #if defined(MACRO) is the same as #ifdef MACRO, but is longer. On the other hand it allows to add extra conditions with || or &&.

    #if MACRO is similar to #ifdef MACRO but not 100%. If MACRO is 0 then #if MACRO will be negative - it requires MACRO to be defined and not be 0. #ifdef checks only whether it is defined even without value (#define MACRO).

    Now is modern to use #if and enable/disable definitions with value 1 or 0:

    #define FLAG_X 1 // or 0

提交回复
热议问题