What exactly does an #if 0 … #endif block do?

后端 未结 9 1475
眼角桃花
眼角桃花 2020-12-02 04:38

In C/C++

What happens to code placed between an #if 0/#endif block?

#if 0

//Code goes here

#endif
         


        
9条回答
  •  庸人自扰
    2020-12-02 05:24

    It is a cheap way to comment out, but I suspect that it could have debugging potential. For example, let's suppose you have a build that output values to a file. You might not want that in a final version so you can use the #if 0... #endif.

    Also, I suspect a better way of doing it for debug purpose would be to do:

    #ifdef DEBUG
    // output to file
    #endif
    

    You can do something like that and it might make more sense and all you have to do is define DEBUG to see the results.

提交回复
热议问题