Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!romp!auschs!awdprime!sanders.austin.ibm.com!sanders From: sanders@peyote.cactus.org (Tony Sanders) Newsgroups: comp.lang.c Subject: Re: Token Pasting Keywords: C, preprocessor, ##, # variable Message-ID: <5256@awdprime.UUCP> Date: 12 Feb 91 00:25:58 GMT References: <2261@enuxha.eas.asu.edu> <1991Feb11.195439.17787@csrd.uiuc.edu> Sender: news@awdprime.UUCP Reply-To: sanders@peyote.cactus.org (Tony Sanders) Organization: IBM AWD, Austin Lines: 31 Originator: sanders@sanders.austin.ibm.com In article <1991Feb11.195439.17787@csrd.uiuc.edu> bliss@sp64.csrd.uiuc.edu (Brian Bliss) writes: > #define init(keyword) keyword ## _symbol = \ > symbol_alloc ("keyword", keyword ## _type) should be: #ifdef __STDC__ #define init(keyword) keyword ## _symbol = \ symbol_alloc (# keyword, keyword ## _type) #else #define init(keyword) keyword ## _symbol = \ symbol_alloc ("keyword", keyword ## _type) #endif Which I use like this: #ifdef __STDC__ #define DPV(variable,type) if (debug) fprintf(stderr, \ "%s:%d, " # variable " = %" # type "\n",__FILE__,__LINE__,variable) #else #define DPV(variable,type) if (debug) fprintf(stderr, \ "%s:%d, variable = %type\n",__FILE__,__LINE__,variable) #endif It's quite ugly but it works great. Your mileage may vary. This works because # keyword converts to "expaned_keyword" and "foo" "bar" "bat" "baz" converts to "foobatbatbaz". -- sanders@peyote.cactus.org First rule of software: Throw the first one away. and so on... I am not an IBM representative and I speak only for myself.