[net.unix-wizards] Comments in C

dan@BBN-UNIX@sri-unix (11/18/82)

From: Dan Franklin <dan at BBN-UNIX>
Date: 14 Nov 1982 13:51:09 EST (Sunday)
I disagree; I'm glad comments don't nest.  If they did, every time I forgot a
'*/' it would eat up the entire rest of the program, as opposed to the current
situation where it only eats up until the next comment.  This makes it 
considerably easier to find the missing close-comment.  (Especially since I
have a program which can, among other things, point out embedded comments.)

    Dan

sch2@MITRE-BEDFORD@sri-unix (11/21/82)

Date: Thu Nov 18 08:01:11 1982
I think there are merits for and against comments nesting.  How about having
the compiler give something like:
	warning: nested comment
and the line number would be where it started.  Suppose you modify your
C compiler to support nested comments, IT WON'T BE PORTABLE and therefore
should produce a warning.  The present situation is a user trap, but
personally I think nested comments would provide an even bigger user trap.
			Why am I bothering discussing this?
			S. Hemminger

fred.umcp-cs@UDel-Relay@sri-unix (11/23/82)

From:     Fred Blonder <fred.umcp-cs@UDel-Relay>
Date:     18 Nov 82 17:05:00 EST  (Thu)
From: Dan Franklin <dan at BBN-UNIX>

	I'm glad comments don't nest.  If they did, every time I forgot
	a '*/' it would eat up the entire rest of the program, as
	opposed to the current situation where it only eats up until
	the next comment.  This makes it considerably easier to find
	the missing close-comment.  (Especially since I have a program
	which can, among other things, point out embedded comments.)

	    Dan

If the C preprocessor gave you an error message of the form:

	WARNING: nonterminated comment begins on line 376

(a not unreasonable request) It'd be just as easy to find the missing ``*/''
and you wouldn't need to run your program.

dan@BBN-UNIX@sri-unix (11/24/82)

From: Dan Franklin <dan at BBN-UNIX>
Date: 23 Nov 1982  0:47:28 EST (Tuesday)
I think the subject's been just about beaten to death, but: yes, whether
comments nest or not, a friendly compiler can point out a problem ('unterminated
comment at line #' or 'comment within comment at line #'), and an unfriendly
compiler can be equally useless either way.  I do not believe that if comments
nested, cc would necessarily diagnose errors for you; as evidence I submit the
fact that although #if and #endif nest, if you forget an #endif the V7
preprocessor gives you the "silent treatment" that UNIX is so justly famed for.
(It is also slightly more difficult to handle nested comments correctly, since
you have to keep a stack of starting comment line numbers, but of course anyone
who sets out to write a compiler shouldn't find that particularly daunting!)

If anyone is seriously thinking of changing the compiler, I really think that
changing it to warn about comments within comments, rather than changing it to
make comments nest, is more appropriate--compatibility being a lot more
important than immediate convenience.  But the right place to put such a check
is probably in lint, given the current situation.

    Dan

minow (11/25/82)

I would strongly recommend not allowing comments to nest, and printing
a warning message if "/*" is seen within a comment.  This is trivial
to do.

Things would be really nice if C allowed a "comment from here to end
of line" facility.

Martin Minow
decvax!minow

mark.umcp-cs@Udel-Relay@sri-unix (11/28/82)

From:     Mark Weiser <mark.umcp-cs@Udel-Relay>
Date:     26 Nov 82 10:34:00 EST  (Fri)
I would strongly recommend not allowing comments to nest, and printing
	a warning message if "/*" is seen within a comment.  
No reason?

mayer (11/28/82)

If C supported "comment to end of line" there would be no problem with
non terminated comments!
					Jim Mayer

gwyn@Brl@sri-unix (11/29/82)

From:     Doug Gwyn <gwyn@Brl>
Date:     28 Nov 82 3:39:55-EST (Sun)
I imagine some folks are tired of the topic, but ...
Here is a real live example of the utility of allowing /* inside comments:

	if ( (ushort)uid == sbuf.st_uid )
		mode <<= 6;		/* check user field only */
	else if ( (ushort)getgid() == sbuf.st_gid )
		mode <<= 3;		/* check group field only */
/*	else
/*		mode <<= 0;		/* check other field only */

mn (11/29/82)

I, for one think that comments in 'C' work fine.
The following has been suggested:

Here is a real live example of the utility of allowing /* inside comments:
if ( (ushort)uid == sbuf.st_uid )
		mode <<= 6;		/* check user field only */
	else if ( (ushort)getgid() == sbuf.st_gid )
		mode <<= 3;		/* check group field only */
/*	else
/*		mode <<= 0;		/* check other field only */

I maintain that a better way to "comment" out a section of code is 
with ifdef-endif like this:

if ( (ushort)uid == sbuf.st_uid )
		mode <<= 6;		/* check user field only */
	else if ( (ushort)getgid() == sbuf.st_gid )
		mode <<= 3;		/* check group field only */
#ifdef OTHER
	else
		mode <<= 0;		/* check other field only */
#endif		
	
	Sure it's more to type, however if one decides to reinstall the
commented out code you don't have to wade though the source with an
editor. And ifdef's nest.

	Just to get my $.02 in.
	Mark Nettleingham
	(...!ihldt!ll1!mn)

ignatz (11/30/82)

	"Comment to end of line"????
	What's a line?
	I'm not supposed to know THAT, am I???

			Your local friendly 'C' compiler

spoon (12/01/82)

C comments has, in fact, been beaten to death.  To those who
would like to have the compiler report nested comments and so on
the Mark William Co. Coherent C compiler does produce
warning messages on these and a variety of other topics.

gwyn@Brl@sri-unix (12/08/82)

From:     Doug Gwyn <gwyn@Brl>
Date:     1 Dec 82 15:38:50-EST (Wed)
The point of my example was not "code that was commented out and may
want to be put back later".  It was code that was not wanted except
for documentary purposes and was written that way in the first place.