1234567891011121314151617181920212223242526 |
- [Main]
- Title=Deleted Code
- [Top]
- 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.
- <BR><BR>
- One way to avoid this problem is to use an always-false conditional
- instead. For instance, put <CODE>#if 0</CODE> before the deleted code and
- <CODE>#endif</CODE> after it. This works even if the code being turned
- off contains conditionals, but they must be entire conditionals
- (balanced <CODE>#if</CODE> and <CODE>#endif</CODE>).
- <BR><BR>
- Some people use <CODE>#ifdef notdef</CODE> instead. This is risky, because
- <CODE>notdef</CODE> might be accidentally defined as a macro, and then the
- conditional would succeed. <CODE>#if 0</CODE> can be counted on to fail.
- <BR><BR>
- Do not use <CODE>#if 0</CODE> for comments which are not C code. Use a real
- comment, instead. The interior of <CODE>#if 0</CODE> must consist of complete
- tokens; in particular, single-quote characters must balance. Comments
- often contain unbalanced single-quote characters (known in English as
- apostrophes). These confuse <CODE>#if 0</CODE>. They don't confuse
- <CODE>/*</CODE>.
|