Nested Comments in C -- A recent experience

Karl Heuer karl at haddock.ima.isc.com
Mon Mar 26 09:42:18 AEST 1990


In article <5418 at jarthur.Claremont.EDU> dfoster at jarthur.Claremont.EDU (Derek R. Foster) writes:
>In article <1990Mar18.045238.18224 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>>As has been explained at length, several times, this is a thoroughly bad
>>idea that programmers eventually learn to avoid.  It simply doesn't work
>>as well as #ifdef.
>
>You forgot to add "IN MY HUMBLE (or maybe not so humble, considering the
>above statement) OPINION!"

FACT: any modern C compiler will support #if...#endif, whereas comment nesting
is a local hack that happens to work on YOUR compiler.  In this sense, at
least, #if...#endif is a better choice.

Now, GIVEN that you like to program in a dialect that supports both
#if...#endif and comment nesting, and that you don't care about porting code
containing nested comments to Standard C, I suppose it's a matter of opinion
which one works better.

My OPINION is that #if...#endif is still a better choice, since it avoids
having to worry about how the local dialect handles quote-and-comment mixing,
and since it allows me to specify a condition to enable/disable the section of
code without having to edit the program source.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list