DEBUG macros in C++

后端 未结 9 1938
谎友^
谎友^ 2020-12-07 07:54

I just encountered a DEBUG macro in C that I really like

#ifdef DEBUG_BUILD
#  define DEBUG(x) fprintf(stderr, x)
#else
#  define DEBUG(x) do {} while (0)
#e         


        
9条回答
  •  星月不相逢
    2020-12-07 08:39

    I use following micro,

    #if DEBUG
    #define LOGE2(x,y) std::cout << "ERRO : " << "[" << __FILE__ << "][" << __FUNCTION__ << "][Line " << __LINE__ << "] " << x <<":"<< y <

    USE:

    LOGE("ERROR.");
    LOGE2("ERROR1","ERROR2");
    

提交回复
热议问题