comment style

Walter Bright bright at nazgul.UUCP
Tue Jan 15 13:46:30 AEST 1991


In article <4423 at alliant.Alliant.COM> tj at Alliant.COM (Tom Jaskiewicz) writes:
<If you do add // comments to c, what does the following code do?
</*	printf("One\n");	/* 1 */
<	printf("Two\n");	/* 2 */
</*	printf("Three\n");
<//	printf("Four\n");	/* 4 */
<	printf("Five\n");	/* 5 */
<//	printf("Six\n");	/* 6
<	printf("Seven\n");	/* 7 */
</*	printf("Eight\n");
<// */	printf("Nine\n");
<	printf("Ten\n");	/* 10 */

Removing commented out structures we get:
	printf("Two\n");
	printf("Five\n");
	printf("Seven\n");
	printf("Nine\n");
	printf("Ten\n");

No problem. The rules to remember are:
o	When inside a comment, the only thing recognized is an end-of-comment
	for the type of comment you're inside. If you're in a /* comment,
	characters are eaten until you see a */. If you're in a //
	comment, characters are eaten until you see a newline.
o	As a corollary, comments do not nest.
o	Backslashes \ that terminate a line are removed and lines are
	spliced *before* comment processing is done. (Anything else would
	cause a major monkey wrench into the ANSI C phases of translation
	verbage.) This means that:

	a = b; // this \
	text is part of the comment!

	a = b; /\
	/ this text is a comment!

	a = b; /* *\
	/ "this text is not part of a comment!";

	The idea behind \ line splicing is that it can be done in a very
	simple context-free manner.



More information about the Comp.std.c mailing list