DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Complying with standard C

Token pasting

In pre-ANSI C compilers, there were at least two ways to combine two tokens. Both invocations in the following produced a single identifier x1 out of the two tokens x and 1.

   #define self(a) a
   #define glue(a,b) a/**/b        ++
   self(x)1
   glue(x,1)
ANSI C could not sanction either approach to what they believed to be an important capability. In ANSI C, both the above invocations would produce the two separate tokens x and 1. The second of the above two methods can be rewritten for ANSI C by using the ## macro substitution operator:
   #define glue(a,b) a ## b
   glue(x, 1)
Since ## is an actual operator, the invocation can be much freer with respect to white space in both the definition and invocation.

There is no direct approach to effect the first of the two old-style pasting schemes, but since it put the burden of the pasting at the invocation, it was used less frequently than the other form.


NOTE: # and ## should be used as macro substitution operators only when __STDC__ is defined.


Next topic: Using const and volatile
Previous topic: Stringizing

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004