Deleted Code
4.3 Deleted Code
If you replace or delete a part of the program but want to keep the old code around for future reference, you often cannot simply comment it out. Block comments do not nest, so the first comment inside the old code will end the commenting-out. The probable result is a flood of syntax errors.
One way to avoid this problem is to use an always-false conditional instead. For instance, put #if 0
before the deleted code and #endif
after it. This works even if the code being turned off contains conditionals, but they must be entire conditionals (balanced ‘#if
’ and ‘#endif
’).
Some people use #ifdef notdef
instead. This is risky, because notdef
might be accidentally defined as a macro, and then the conditional would succeed. #if 0
can be counted on to fail.
Do not use #if 0
for comments which are not C cod