#ifdef vs #if - which is better/safer as a method for enabling/disabling compilation of particular sections of code?

后端 未结 19 868
忘了有多久
忘了有多久 2020-11-30 17:26

This may be a matter of style, but there\'s a bit of a divide in our dev team and I wondered if anyone else had any ideas on the matter...

Basically, we have some de

19条回答
  •  天涯浪人
    2020-11-30 18:05

    They're both hideous. Instead, do this:

    #ifdef DEBUG
    #define D(x) do { x } while(0)
    #else
    #define D(x) do { } while(0)
    #endif
    

    Then whenever you need debug code, put it inside D();. And your program isn't polluted with hideous mazes of #ifdef.

提交回复
热议问题