define end of comment

Col. G. L. Sicherman colonel at ellie.UUCP
Wed Apr 23 06:52:50 AEST 1986


> 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 at buffalo-cs
BI: csdsicher at sunyabva



More information about the Comp.lang.c mailing list