Token Pasting

Brian Bliss bliss at sp64.csrd.uiuc.edu
Tue Feb 12 06:54:39 AEST 1991


In article <2261 at enuxha.eas.asu.edu>, hurwitz at enuxha.eas.asu.edu (Roger
A. Hurwitz) writes:
|> 
|> I have heard about token pasting, and I have fooled around with
|> the C ## preprocessor operator, but I do not understand the
|> need for this capability.  Could someone provide an example
|> of when/where/how token pasting comes in handy?
|> 
|> Thanks,
|> Roger Hurwitz
|> hurwitz at enuxha.eas.asu.edu

 The last time I needed to do it was when writing a debugger.
 For each simple type, I had an associated type descriptor and 
 symbol. so I needed to say:

 #define init(keyword)	keyword ## _symbol = \
                           symbol_alloc ("keyword", keyword ## _type) 

 init (int)
 init (short)
 init (long)

  etc.

 when I tried to port the thing, the token pasting didn't work,
 putting a macro argument inside a string didn't result in
 the correct substitution, etc., so I gave up and hard-coded
 the whole damn thing.

 bb



More information about the Comp.lang.c mailing list