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

vette982 picture vette982 · May 17, 2010 · Viewed 99.1k times · Source

In C/C++

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

#if 0

//Code goes here

#endif

Does the code simply get skipped and therefore does not get executed?

Answer

David picture David · May 17, 2010

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.