Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!news.cs.indiana.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!sp64.csrd.uiuc.edu!bliss From: bliss@sp64.csrd.uiuc.edu (Brian Bliss) Newsgroups: comp.lang.c Subject: Re: Token Pasting Keywords: C, preprocessor, ## Message-ID: <1991Feb11.195439.17787@csrd.uiuc.edu> Date: 11 Feb 91 19:54:39 GMT References: <2261@enuxha.eas.asu.edu> Sender: news@csrd.uiuc.edu (news) Reply-To: bliss@sp64.csrd.uiuc.edu (Brian Bliss) Organization: Center for Supercomputing Research and Development Lines: 31 In article <2261@enuxha.eas.asu.edu>, hurwitz@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@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