[net.lang.c] Standardization questions -- nested comments

ron@brl-tgr.ARPA (Ron Natalie <ron>) (10/12/84)

If you make /* */ nest, then you will incur the wrath of the
people who comment code out with the correct and documented
behavior of comments.  By the way, it isn't that /* */ doesn't
nest properly, they don't nest at all.

There already is a facility called conditional compilation that
does what you want.  Like

	#ifdef NOT_TODAY
		/*
		 *  This code is only to be run on February 31.
		 */
		while(n--) n++;
	#endif

-Ron

rcd@opus.UUCP (Dick Dunn) (10/12/84)

One recent idea was to have an occurrence of "/*" within a comment generate
a warning.  I suppose I could live with that as long as I can shut off
the warning (since I would use an alias or some such to disable it all
the time).  Another suggestion:

> From:   Paul Schauble <Schauble@MIT-MULTICS.ARPA>
> 
> Has anyone considered making /* and */ nest properly, so that one could
> comment out commented code??

It bothers me a little that it seems necessary to start complicating the
structure of comments.  For C, I really think we can live with what we've
got.  In another language design, there are probably better ways to
go--such as Ada's "--" which is ALWAYS terminated at end of line.
(Commenting out a section of code is easy; just prefix each line with --.)
Another approach is to have two forms such as (* *) vs { } in Pascal BUT
don't allow matching (* with } or { with *)--this is clumsier but can be
made to work.

Examining the interior of comments CAN get in the way.  Once upon a time
there was a not-quite-brilliant idea that Pascal compilers should make an
effort to detect an unclosed comment.  (I think it was in one of the drafts
of the Standard; I have no idea whether it stayed.)  This begat some odd
solutions--one of the worst being a compiler warning on any occurrence of a
semicolon within a comment.  Of course, if you write normal text in
comments you'll punctuate it and the compiler makes a lot of racket.  So
you turn off warning messages and miss all of the nice things like "this
variable is probably used before it is set."
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Relax...don't worry...have a homebrew.

jon@boulder.UUCP (Jon Corbet) (10/12/84)

I do not see the need for nested comments.  The old idiom

# ifdef notdef
	.
	commented code
	.
# endif

works wonderfully, no matter how many comments are in the affected area.

--
Jonathan Corbet
National Center for Atmospheric Research, Field Observing Facility

warren@tikal.UUCP (10/12/84)

[Ignore this message ]

	C provides an excellent construct for commenting out commented code:
	#if 0
		blah, blah
	#endif

						teltone!warren

mark@tove.UUCP (Mark Weiser) (10/14/84)

> From:  William LeFebvre <phil@RICE.ARPA>
> 
> > Has anyone considered making /* and */ nest properly, so that one could
> > comment out commented code??
> 
> The best and most widely accepted way to prevent a block of code from
> being compiled while still leaving the code in the file is as follows:
> 
> #ifdef notdef

The serious problem with no nesting is that whether or not a comment
will work or net depends on the context.  The #ifdef method is
ugly, and only works for sure if you never use comments or keep them
real short.  If there is any chance that a comment may be lurking
around, one cannot just stick a comment string into a C file without
checking an arbitrarily large amount of context information to see
if there is another comment that it will mung.  This sort of global
checking is just the sort of things I hate to do, but computers are
good at.  Let's hear it for compiler support for nested comments.
-- 
Spoken: Mark Weiser 	ARPA:	mark@maryland
CSNet:	mark@umcp-cs 	UUCP:	{seismo,allegra}!umcp-cs!mark
U.S.: Computer Science Dept., University of Maryland, College Park, MD 20742

tim@callan.UUCP (Tim Smith) (10/16/84)

from someone:
> Has anyone considered making /* and */ nest properly, so that one could
> comment out commented code??

I would like to see comments introduced by something like '##', and terminate
at the end of a line.  I think this is nicer looking, and it is consistent
with comments in other places, such as 'make', the shells, etc.

from someone else:
>The best and most widely accepted way to prevent a block of code from
>being compiled while still leaving the code in the file is as follows:
>
>#ifdef notdef

But what if notdef is defined?  Clearly, you want

#ifdef  notdef
#ifndef notdef
	code code code code /* but I don't like code! */ wonderfull code
#endif
#endif

This will always work! :-)
-- 
					Tim Smith
			ihnp4!wlbr!callan!tim or ihnp4!cithep!tim

rcd@opus.UUCP (Dick Dunn) (10/16/84)

> > From:  William LeFebvre <phil@RICE.ARPA>
> > > Has anyone considered making /* and */ nest properly, so that one could
> > > comment out commented code??
> > The best and most widely accepted way to prevent a block of code from
> > being compiled while still leaving the code in the file is as follows:
> > #ifdef notdef
> The serious problem with no nesting is that whether or not a comment
> will work or net depends on the context.  The #ifdef method is
> ugly, and only works for sure if you never use comments or keep them
> real short...

Ugliness is in the eye of the person who doesn't want to do it that way...
but seriously, what's the problem of interaction with comments?

> ...If there is any chance that a comment may be lurking
> around, one cannot just stick a comment string into a C file without
> checking an arbitrarily large amount of context information to see
> if there is another comment that it will mung.  This sort of global
> checking is just the sort of things I hate to do, but computers are
> good at.  Let's hear it for compiler support for nested comments.

It seems like the argument here is that you want to be able to comment out
code without any attention to the context.  That won't work, and nesting
comments won't help.

Oh, by the way, would one of the comment-nesting advocates care to tell us
whether a comment delimiter in quotes--say "/*"--should be regarded as a
delimiter or not?  Don't consider this one for too long--either answer
leads to annoying situations.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Lately it occurs to me what a long, strange trip it's been.

lat@stcvax.UUCP (Larry Tepper) (10/16/84)

If one insists on usings comments to comment out code, instead
of using "#ifdef notdef", just begin each line with "/*".
Fer instance:

/* Comment-out this loop until we know the hardware works...
/*	for (i = 0; i < whatever; i++)  {	/* this is a comment */
/*		/* so on and so forth... */
/*		....
/*	}
/* End of commented section */

All that's required to make this easy with an editor is
to delimit the section with some token quickly recognizable
by you, the programmer, rather like the !Funky!Stuff! delimiter
in various shar programs.

Regardless, you still have to examine the code that you intend
to comment-out.  Even with nested comments, a blind approach
might carelessly comment out an "#endif".
-- 
Violence is the last refuge of the incompetent.

{ihnp4 hao philabs sdcrdcf ucbvax!nbires}!stcvax!lat	Larry Tepper
Storage Technology, MD-3T, Louisville, CO 80028		303-673-5435

ron@brl-tgr.ARPA (Ron Natalie <ron>) (10/17/84)

> The serious problem with no nesting is that whether or not a comment
> will work or net depends on the context.

Correct, and all you are doing is changing the context rules from one to
another by making comments nest.

> The #ifdef method is
> ugly, and only works for sure if you never use comments or keep them
> real short.  If there is any chance that a comment may be lurking
> around, one cannot just stick a comment string into a C file without
> checking an arbitrarily large amount of context information to see
> if there is another comment that it will mung.

Eh?  #ifdef only has the problem that C has in general, unterminated
comments.  A lint warning about comment ambiguity is required whether
you nest or not.

If you don't nest (current):

	/* COMMENT
		comment_code;  /*  Comment in comment */
	 */

The comment is terminated early and the */ is unexpected and generates
a comile error or
	/*  Comment missing end.
	real_code;	/*  Comment */

No compile error results but read_code gets mysteriously deleted.

If you do nest:
	/*  Commented code	/* commented comment */
	real_code
rest of the file gets eaten (but doesn't if you use the current correct
syntax)... etc...

You probably need to be able to get nit-picking warnings about comments
in comments, comments unterminated at end of file, etc...

Just anot her gratuitous change to the C language that breaks existing
correct code and does not really solve any problems.


-Ron "Let's keep C, C." Natalie