Monday, February 23, 2009

Commenting out code with the preprocessor

Because C and C++ do not allow nesting comments with /* and */, it can be a hassle to comment out long regions of code.

For instance, you cannot do this:

/* First layer
/* Second layer */
*/


because the first */ closes the entire comment!


Fortunately, the preprocessor can help you: you can use the #if .. #endif combination to cause the preprocessor to avoid compiling any portion of your code by using a condition that will never be true.

#if 0
/* comment */
/* code */
/* comment */
#endif



Author : Webmaster

0 nhận xét:

Post a Comment