Macro to turn off printf statements

后端 未结 10 1623
粉色の甜心
粉色の甜心 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条回答
  •  旧时难觅i
    2020-12-14 08:46

    I use to prefix the debug printf()s (not all of them) with PDEB.

    For the debug builds, I compile with -DPDEB= (nothing)

    For the release builds, I compile with -DPDEB="0&&" or -DPDEB="0 && "

    That way, the following code (test.c):

    #include 
    
    void main(void) {
    
            printf("normal print\n");
    
            PDEB printf("debug print\n");
    }
    

    outputs: either (in release mode): normal print

    either (in debug mode): normal print debug print

    Ideally, one could aim for turning the PDEB into the "//" (comments mark), except that this is not possible under the standard pre-/processing chain.

提交回复
热议问题