Article View: comp.std.c
Article #3883Re: Can somebody explain how or when I can use "#if 0"?
From: Nick Maclaren
Date: Mon, 28 Aug 1995 14:01
Date: Mon, 28 Aug 1995 14:01
42 lines
2069 bytes
2069 bytes
In article <41rqbi$i3o@zonker.cs.ucsb.edu>, Steve E. Chapel <schapel@zonker.cs.ucsb.edu> wrote: >kanghoon@ix.netcom.com (Kang H. Lee ) writes: > >>I was looking at some code, and found this preprocessor: > >>#if 0 >> .... >>#else >> .... >>#endif > >>Can somebody explain to me clearly how this works? > >I use this sometimes when I'm trying out two different pieces of code >and want to be able to switch between them quickly. If I change the >0 to a 1, the first section rather than the second section is used. > >More often than that trick, I use just #if 0 ... #endif to temporarily >remove one section of code. It's safer than commenting out, because >if there are any comments inside the section, commenting out the >section won't work. This is the usual reason, but be warned that SOME compilers will parse (or partially parse) some of the excluded text. You should therefore not use this trick to exclude syntactically invalid C. The reason for this problem is that the standard is unclear in this area. >By the way, these constructs should normally not appear in finished code. >I use them (I hope) exclusively in code that I'm currently writing or >changing. I take them out when I'm done. There is one case where they SHOULD appear in finished code: that is where the code is left as an example, and cannot be used without further editing. I use '#if 0 == 1' AND comment the code in such cases. Nick Maclaren, University of Cambridge Computer Laboratory, New Museums Site, Pembroke Street, Cambridge CB2 3QG, England. Email: nmm1@cam.ac.uk Tel.: +44 1223 334761 Fax: +44 1223 334679
Technical Details
Message-ID:
<41si6s$4qs@lyra.csx.cam.ac.uk>Path:
arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1References:
<41rm39$o1m@ixnews5.ix.netcom.com> <41rqbi$i3o@zonker.cs.ucsb.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1 From: nmm1@cus.cam.ac.uk (Nick Maclaren) Newsgroups: comp.std.c Subject: Re: Can somebody explain how or when I can use "#if 0"? Date: 28 Aug 1995 14:01:00 GMT Organization: University of Cambridge, England Message-ID: <41si6s$4qs@lyra.csx.cam.ac.uk> References: <41rm39$o1m@ixnews5.ix.netcom.com> <41rqbi$i3o@zonker.cs.ucsb.edu> NNTP-Posting-Host: bootes.cus.cam.ac.uk