#define macro for debug printing in C?

后端 未结 12 1655
夕颜
夕颜 2020-11-21 23:59

Trying to create a macro which can be used for print debug messages when DEBUG is defined, like the following pseudo code:

#define DEBUG 1
#define debug_prin         


        
12条回答
  •  天涯浪人
    2020-11-22 00:28

    This is what I use:

    #if DBG
    #include 
    #define DBGPRINT printf
    #else
    #define DBGPRINT(...) /**/  
    #endif
    

    It has the nice benefit to handle printf properly, even without additional arguments. In case DBG ==0, even the dumbest compiler gets nothing to chew upon, so no code is generated.

提交回复
热议问题