Question 10.20

I have some old code that tries to construct identifiers with a macro like

#define Paste(a, b) a/**/b
but it doesn't work any more.


It was an undocumented feature of some early preprocessor implementations (notably John Reiser's) that comments disappeared entirely and could therefore be used for token pasting. ANSI affirms (as did K&R1) that comments are replaced with white space. However, since the need for pasting tokens was demonstrated and real, ANSI introduced a well-defined token-pasting operator, ##, which can be used like this:

	#define Paste(a, b) a##b
See also question 11.17.

References: ANSI Sec. 3.8.3.3
ISO Sec. 6.8.3.3
Rationale Sec. 3.8.3.3
H&S Sec. 3.3.9 p. 52


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback