C needs reliable comments

P E Smee exspes at gdr.bath.ac.uk
Fri Jan 18 21:04:48 AEST 1991


In article <2893 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
>The discussion of // comments started me thinking.  Did you realize
>that C is one of the few programming languages, perhaps the only one,
>in which you can never be sure of correctly commenting stuff out?

Actually, there are lots of them.

>(a) You can use /* and */ to comment out a block of code.  Then
>anywhere in that block, if a */ occurs, the comment terminates
>prematurely.
>
>C badly needs a way of commenting out a block easily.  It needs
>something like this:
>
>#comment  /* begins in column 1; everything following is a comment */
>... stuff to be commented out ...
>... nac esu #tnemmoc ot peek logla sersu yppah ...
>#endc    /* first occurrence of #endc in column one ends #comment block */
>
>The #comment...#endc blocks do not nest, and are required to be in
>column 1, thus avoiding all necessity for parsing tokens.  

No, this proposal is totally isomorphic with /*-*/ comments.  All you
have done is replace the 'meta-operator' /* with <newline>#comment, and
replace */ with <newline>#endc.  If you try to #comment out a block of
code which already contains a #-comment block, everything falls apart.
(IMHO) you MUST invent some form of nesting comment in order to get the
effect you want.  That has its own set of difficulties, which is why it
is such an uncommon feature.

-- 
Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK
 P.Smee at bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132



More information about the Comp.std.c mailing list