[net.lang.c] define end of comment

colonel@ellie.UUCP (Col. G. L. Sicherman) (04/22/86)

> When in a comment, no expansion is done! 
> 
> How do we then define something which is to end a comment? I would say
> it is impossible, but is eager to hear of anybody who thinks otherwise.

You can do it with bsd4.3 cc.  Here's a program before preprocessing:

#define SLASH	/
#define STAR	*
#define	CSTART		/STAR
#define ALT_CSTART	SLASH*
#define CEND	 	STAR/

main() {
/*
 *	Demonstrate how the Preprocessor handles comments.
 */

/*
 *	It knows that this is a comment, so the next line is not expanded:
 CEND
	printf("Roses are red.\n");
 */
CSTART
 *	It does not know that this is a comment,
 *	so it expands the end-comment token:
 CEND
	printf("Lemons are blue.\n");
ALT_CSTART
 *	But it recognizes this as a comment!  The end-marker is ignored:
 CEND
	printf("Lobsters are yellow.\n");
/*
 */

And here's the output from cpp, with extraneous blank lines deleted:

# 1 ""
main() {
	/*
 *	It does not know that this is a comment,
 *	so it interprets the end-comment token:
  	*/
	printf("Lemons are blue.\n");
}

My entry in the '85 Obfuscated C contest relied on this barfufeature.
-- 
Col. G. L. Sicherman
UU: ...{rocksvax|decvax}!sunybcs!colonel
CS: colonel@buffalo-cs
BI: csdsicher@sunyabva