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

后端 未结 9 1428
眼角桃花
眼角桃花 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:07

    Not only does it not get executed, it doesn't even get compiled.

    #if is a preprocessor command, which gets evaluated before the actual compilation step. The code inside that block doesn't appear in the compiled binary.

    It's often used for temporarily removing segments of code with the intention of turning them back on later.

提交回复
热议问题