home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20237 < prev    next >
Encoding:
Internet Message Format  |  1993-01-27  |  1.5 KB

  1. 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
  2. From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Preprocessor question
  5. Keywords: Preprocessor, string
  6. Message-ID: <1k44lqINNjr3@rs2.hrz.th-darmstadt.de>
  7. Date: 26 Jan 93 19:50:18 GMT
  8. References: <1993Jan25.161425.27962@bnrmtl.bnr.ca> <mick.728072797@picus>
  9. Organization: TH Darmstadt
  10. Lines: 27
  11. NNTP-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
  12.  
  13. In article <mick.728072797@picus>, mick@dcs.bbk.ac.uk (Mick Farmer) writes:
  14. > Hi,
  15. > Karim asks how to get a preprocessor macro recognised inside
  16. > a string.  The answer, at least in ANSI C, is to use the
  17. > stringising operator and string concatenation:
  18. > #define JUNK 50
  19. > static char *junk = #JUNK " ways to leave your lover"
  20.                       ^^^^^
  21. Nope, #token works only with #defines like in:
  22. #define stringify(x) #x
  23. #define str_exp(x) stringify(x)        /* this extra level IS necessary */
  24. static char *junk = str_exp(JUNK) "ways ....";
  25.  
  26. I once encountered a Compiler (Aztec C on Amiga) which would translate
  27. your code, but it isn't ANSI (gcc for example barfs at that: parse error 
  28. before `#').
  29.  
  30.  
  31. > The construct #JUNK generates the string "50", which is
  32. > concatenated with its neighbour.
  33.  
  34. -- 
  35. Walter Misar                                | It is impossible to enjoy
  36. misar@rbg.informatik.th-darmstadt.de        | idling thoroughly unless
  37.                                             | one has plenty of work to do.
  38.