Unterminated comments

apratt at iuvax.UUCP apratt at iuvax.UUCP
Wed Oct 31 06:56:00 AEST 1984


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



More information about the Comp.lang.c mailing list