[net.lang.c] Unterminated comments

phil@RICE.ARPA (10/15/84)

From:  William LeFebvre <phil@RICE.ARPA>

> 	(1)  Nested comments /* ... A ... /* ... B ... */ ... A ... */
>	(2)  Comment-to-end-of-line // ...
> (1) would also give an "unterminated comment starting on line nnn" error
> if a close-comment */ were omitted, thereby addressing in a different
> way the issue this note is a response to.

NO!!!  You do NOT want to do that.  Many people (myself included) write
block comments that purposefully span several lines.  I like that style.
DO NOT force me to change it!  I don't even want to see warning messages
about it.

/*
 *  William LeFebvre
 *  Department of Computer Science
 *  Rice University
 *  <phil@Rice.arpa>
 */

phil@RICE.ARPA (10/22/84)

From:  William LeFebvre <phil@RICE.ARPA>

Okay.  I may have misinterpreted the message.  Doug, if I jumped on you
without cause then I apologize.

But please tell me exactly what you meant.  I am interested.  You said:

--------------------
	(1)  Nested comments /* ... A ... /* ... B ... */ ... A ... */
	(2)  Comment-to-end-of-line // ...
(1) would also give an "unterminated comment starting on line nnn" error
if a close-comment */ were omitted, thereby addressing in a different
way the issue this note is a response to...
--------------------

I took the phrase "if a close-comment */ were omitted" to mean a close
comment for any open comment.  Looking at it again I see that it could
have implied "a close-comment" in the context of "/* ... /* ... */ ... */".
So do you mean that the warning message would be given only if the
comment nesting level was greater than one at some point on the line?

Along the same lines, what about comments like:

	/* if input is "/*" then start throwing away characters */

Or worse yet (a sloppy style):

	/* if input is /* then start throwing away characters */

My main objection is that the only characters that have ever had meaning
inside a comment were the comment end characters "*/".  Now you want to
add another sequence.  I am afraid that there are some programs that
were quite legal before that would produce warning (or error) messages
with this change in syntax.  Is that worth worrying about or is it just
picking bones?

                                William LeFebvre
				Department of Computer Science
				Rice University
                                <phil@Rice.arpa>

apratt@iuvax.UUCP (10/30/84)

I think it's clear, when you look again, that the original writer meant
that a program:

main()
{
	printf("Hello!");	/* This is an unclosed comment
	printf("Goodbye!);
}

should produce the error message, "Unclosed comment starting at line 3." The
same error should be generated for this program:

main()
{
/*
 * This program does almost nothing
 *
	printf("Hello!");
	printf("Goodbye!");
}

(the key word is STARTING at line xx. There's no way of knowing when the
comment was intended to end and the code starts.)

The issue of nested comments is also interesting: time and again I have
wanted to "comment off" code like this:

main()
...
/*
fn1(x,y)		/* real version */
{
	...
}
*/

fn1(x,y)		/* test version */
{
	...
}

But the end-comment after "real version" would close the enclosing comment.
The accepted way to do this, of course, is with #if 0 ... #endif, but I
prefer the nested-comment option stylistically.

The Lattice C compiler for the IBM PC has a nested-comment feature, which
can be turned OFF with a switch on the command line. Very handy, I think.
In the UNIX environment, of course, this kind of thing would be turned ON
with a switch.

----
						-- Allan Pratt
					...ihnp4!inuxc!iuvax!apratt