Nested Comments in C -- A recent experience

Henry Spencer henry at utzoo.uucp
Wed Mar 28 07:41:57 AEST 1990


In article <5418 at jarthur.Claremont.EDU> dfoster at jarthur.Claremont.EDU (Derek R. Foster) 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!"

Me, humble?  I was humble once in 1962; I didn't like it and haven't
repeated it. :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-)

>I have been using nested comments as debugging
>tools for many years, and I have NEVER had a problem with them.

Obviously you never ran into a string containing /*, or the deliberately
mismatched comments used for configuration options in some software packages
and for debugging by some programmers.  As has been explained before, the
stuff inside a comment loses all token structure, which makes it much
easier to encounter "accidental" comment delimiters.  As has been explained
before, because nested comments are not standard C, you can expect to find
code that relies on comments not nesting.  #ifdef has neither problem, and
is also rather more conspicuous when somebody else has to read your code.

>I HAVE had problems with #ifdef and #endif -- they're a lot more trouble
>to use when what I'm debugging is not a completely separate line.

If it's not a completely separate line, it's not likely to have comments
inside it, so regular non-nested comments will suffice.

>Not
>to mention that I can't have my editor jump to matching #ifdef and #endif
>pairs, regardless of nesting, like I can with /* and */ ...

Perhaps you should get a better editor?  They do exist.
-- 
Apollo @ 8yrs: one small step.|     Henry Spencer at U of Toronto Zoology
Space station @ 8yrs:        .| uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list