Wednesday 21 September 2016

How to use #if 0 ... #endif


#if 0
...
#endif

basically tells the compiler that there is no need to compile this part of codes.

Usage:
(1) There might be something needed LATER in the program but we don't yet know exactly how this part works. So just leave it there now without compiling it.

(2) When we want to comment a block of codes using /* ... */, but there are some other comments in this block using  /* ... */, the only option we have is use #if 0 to avoid the compilation of it.

(3) Testing and debugging

#if 0
{original program...}
#else{new program...}
#endif


if we need to change back to the original program, just change the 0 back to 1.

ref:
http://www.programmer-club.com.tw/ShowSameTitleN/c/29150.html

No comments:

Post a Comment