#define macro for debug printing in C?

后端 未结 12 1648
夕颜
夕颜 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:20

    I would do something like

    #ifdef DEBUG
    #define debug_print(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
    #else
    #define debug_print(fmt, ...) do {} while (0)
    #endif
    

    I think this is cleaner.

提交回复
热议问题