When and Why do we use "#if 0"
2006-09-02 15:27
621 查看
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 code. Use a real comment, instead. The interior of #if 0 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 #if 0. They don't confuse /*.
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 code. Use a real comment, instead. The interior of #if 0 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 #if 0. They don't confuse /*.
相关文章推荐
- Why do I get warnings "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"?
- what is WLAN ? when and why we need use it ?
- Why do we get error "Call to undefined function: ora_logon()/ ocilogon()"?
- what is the virtual machine, when and why we need use it ?
- Why use sort() when we have "good old qsort()"?
- Problem When use "Custom Editor" and "Property Drawers" The Same Time
- [Deprecated( "please use panBy and panTo APIs" )]
- zz"Who do you think is the best coder, and why?"zz
- Why Do We Use Fiber Optic Switch?
- 第一篇:解决ADB not responding. If you'd like to retry, then please manually kill "adb.exe" and click 'Res
- Requirement Traceability Matrix (RTM) – What Is RTM And Why Do We Need It?
- 小胖说事31------iOS 真机编译错误"“XXX”的 iPod" and run "XXX" again, or if "XXX" is still running
- Why I can't use non-string key in the myMap[myKey] expression? And what to do now?
- What To Do and Not To Do When 'shutdown immediate' Hangs [ID 375935.1]
- Why use Servlets & JSPs: an introduction(Head First Servlets and JSP)
- test the difference between "DEFAULT NULL" and "DEFAULT 0"
- Longest Subarray with Equal "1" and "0"
- Why do people use Hadoop or Spark when there is ElasticSearch?
- The XML Litmus Test Understanding When and Why to Use XML
- jstl 的if else <c:choose><c:when test="">如果</c:when><c:otherwise>否则</c:otherwise></c:choose>