Token Pasting Operator

The preprocessor token pasting operator can only appear in a preprocessor directive. It which consists of two number signs:

	##

allows tokens used as actual arguments to be pasted to together to form larger tokens. These tokens are not strings as in the stringizing operator, but could (for example) form a larger identifier.

	#define select(a,b)   a##_##b

	int wing_length, engine_length, wing_thickness, engine_diameter;
	...
	select(wing,length)=select(wing,thickness)+select(engine,diameter)+2;

which yields:

    wing_length=wing_thickness+engine_diameter+2;

Note that the resulting token may itself be replaced because of another macro substitution.


© 1991-2008 Prem Sobel. All Rights Reserved.