home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!opl.com!hri.com!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
- Newsgroups: comp.lang.c
- Subject: Re: Preprocessor question
- Keywords: Preprocessor, string
- Message-ID: <1k44lqINNjr3@rs2.hrz.th-darmstadt.de>
- Date: 26 Jan 93 19:50:18 GMT
- References: <1993Jan25.161425.27962@bnrmtl.bnr.ca> <mick.728072797@picus>
- Organization: TH Darmstadt
- Lines: 27
- NNTP-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
-
- 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 ....";
-
- I once encountered a Compiler (Aztec C on Amiga) which would translate
- your code, but it isn't ANSI (gcc for example barfs at that: parse error
- before `#').
-
-
- > The construct #JUNK generates the string "50", which is
- > concatenated with its neighbour.
-
- --
- Walter Misar | It is impossible to enjoy
- misar@rbg.informatik.th-darmstadt.de | idling thoroughly unless
- | one has plenty of work to do.
-