Why nested comments not allowed?

Adrian McCarthy adrian at mti.mti.com
Fri Feb 23 04:55:24 AEST 1990


In article <7060002 at hpfcso.HP.COM> mike at hpfcso.HP.COM (Mike McNelly) writes:
>
>	> I'm just curious to know why nested comments are not allowed in many 
>	> languages.
>
>1.  They have limited usefulness.  For most of the occasions where they
>are useful, conditional compilation seems to work better.  In C, for
>example,

Often, while developing a program, it is useful to comment out a section of
code.  Using conditional compilation for this is about as clumsy as using
nested comments.  Sometimes you want to comment out *part* of a line,
but that is awkward since #ifdef must be at the beginning of a line.  When
you want to comment out larger chunks of code, the #ifdef - #endif lines
are easy to loose site of (especially if your code has lots of #ifdef's for
other reasons).  On top of all that, not all languages have preprocessors.

In practice, it seems we don't really need true nested comments, but simply
two kinds of comments:  regular comments and code omitting comments.  It
seems Pascal almost had it right.  You could use "{" and "}" to delimit
regular comments, and "(*" and "*)" to comment out code.  Alas, most
implementations of Pascal will allow a "*)" to end a comment introduced by
"{".

Aid.

P.S.  I'm working on a macro preprocessor that, unlike the C preprocessor
and m4, will be useful on nearly all types of source code *and*
documentation.  In its default mode, it is an ANSI compliant C preprocessor.
Don't hold your breath though; it'll be awhile before it's done.



More information about the Comp.lang.c mailing list