Macro to turn off printf statements

后端 未结 10 1609
粉色の甜心
粉色の甜心 2020-12-14 08:42

What MACRO can be used to switch off printf statements, rather than removing them all for deployment builds, I just want to switch them off, skip them, ignore them.

10条回答
  •  眼角桃花
    2020-12-14 09:04

    Use this macro to enable or disable the printf.

    //Uncomment the following line to enable the printf function.
    //#define ENABLE_PRINTF
    #ifdef ENABLE_PRINTF
        #define    DEBUG_PRINTF(f,...)    printf(f,##__VA_ARGS__)
    #else
        #define    DEBUG_PRINTF(f,...)
    #endif
    

    Then call "DEBUG_PRINTF" instead of "printf".

    For example:

    DEBUG_PRINTF("Hello world: %d", whateverCount);
    

提交回复
热议问题