home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!usenet.ins.cwru.edu!agate!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!mcsun!sunic!kth.se!news.kth.se!harald
- From: harald@marilyn.bion.kth.se (Harald Winroth)
- Subject: Re: Preprocessor question
- In-Reply-To: srl@terminus.ericsson.se's message of 27 Jan 93 09:48:00 GMT
- Message-ID: <HARALD.93Jan27161551@marilyn.bion.kth.se>
- Sender: usenet@kth.se (Usenet)
- Nntp-Posting-Host: marilyn.bion.kth.se
- Organization: Royal Institute of Technology, Stockholm, Sweden
- References: <1k44lqINNjr3@rs2.hrz.th-darmstadt.de> <1099@quirm.terminus.ericsson.se>
- Date: Wed, 27 Jan 1993 15:15:51 GMT
- Lines: 29
-
- In article <1099@quirm.terminus.ericsson.se> srl@terminus.ericsson.se (Steve Langstaff) writes:
-
- > In article 1k44lqINNjr3@rs2.hrz.th-darmstadt.de, misar@rbg.informatik.th-darmstadt.de (Walter Misar) writes:
- > : In article <mick.728072797@picus>, mick@dcs.bbk.ac.uk (Mick Farmer) writes:
- > : > Hi,
- > : >
- > : > Karim asks how to get a preprocessor macro recognised inside
- > : > a string. The answer, at least in ANSI C, is to use the
- > : > stringising operator and string concatenation:
- > : >
- > : > #define JUNK 50
- > : > static char *junk = #JUNK " ways to leave your lover"
- > : ^^^^^
- > : Nope, #token works only with #defines like in:
- > : #define stringify(x) #x
- > : #define str_exp(x) stringify(x) /* this extra level IS necessary */
- > : static char *junk = str_exp(JUNK) "ways ....";
- > :
- > [snip]
- >
- > Why is the extra level necessary?
-
- Because further macro replacements will not be done for arguments which
- correspond to formal macro parameters adjacent to # or ## in the body.
- stringify(JUNK) will therefore expand to "JUNK", not to "50".
- -----------------------------------------------------------------------------
- Harald Winroth | Computational Vision and Active Perception Laboratory,
- harald@bion.kth.se | Royal Institute of Technology, Stockholm, Sweden.
- -----------------------------------------------------------------------------
-