🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2292

Re: comment style

#2292
From: Walter Bright
Date: Tue, 15 Jan 1991 02:46
42 lines
1787 bytes
In article <4423@alliant.Alliant.COM> tj@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.
Technical Details
Message-ID: <226@nazgul.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!pilchuck!dataio!fnx!nazgul!bright
References: <4423@alliant.Alliant.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!pilchuck!dataio!fnx!nazgul!bright
From: bright@nazgul.UUCP (Walter Bright)
Newsgroups: comp.std.c
Subject: Re: comment style
Message-ID: <226@nazgul.UUCP>
Date: 15 Jan 91 02:46:30 GMT
References: <4423@alliant.Alliant.COM>
Reply-To: bright@nazgul.UUCP (Walter Bright)
Organization: Zortech, Seattle
Lines: 42