home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20293 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.1 KB  |  43 lines

  1. Newsgroups: comp.lang.c
  2. 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
  3. From: harald@marilyn.bion.kth.se (Harald Winroth)
  4. Subject: Re: Preprocessor question
  5. In-Reply-To: srl@terminus.ericsson.se's message of 27 Jan 93 09:48:00 GMT
  6. Message-ID: <HARALD.93Jan27161551@marilyn.bion.kth.se>
  7. Sender: usenet@kth.se (Usenet)
  8. Nntp-Posting-Host: marilyn.bion.kth.se
  9. Organization: Royal Institute of Technology, Stockholm, Sweden
  10. References: <1k44lqINNjr3@rs2.hrz.th-darmstadt.de> <1099@quirm.terminus.ericsson.se>
  11. Date: Wed, 27 Jan 1993 15:15:51 GMT
  12. Lines: 29
  13.  
  14. In article <1099@quirm.terminus.ericsson.se> srl@terminus.ericsson.se (Steve Langstaff) writes:
  15.  
  16. >   In article 1k44lqINNjr3@rs2.hrz.th-darmstadt.de, misar@rbg.informatik.th-darmstadt.de (Walter Misar) writes:
  17. >   : In article <mick.728072797@picus>, mick@dcs.bbk.ac.uk (Mick Farmer) writes:
  18. >   : > Hi,
  19. >   : > 
  20. >   : > Karim asks how to get a preprocessor macro recognised inside
  21. >   : > a string.  The answer, at least in ANSI C, is to use the
  22. >   : > stringising operator and string concatenation:
  23. >   : > 
  24. >   : > #define JUNK 50
  25. >   : > static char *junk = #JUNK " ways to leave your lover"
  26. >   :                       ^^^^^
  27. >   : Nope, #token works only with #defines like in:
  28. >   : #define stringify(x) #x
  29. >   : #define str_exp(x) stringify(x)        /* this extra level IS necessary */
  30. >   : static char *junk = str_exp(JUNK) "ways ....";
  31. >   : 
  32. >   [snip]
  33. >
  34. >   Why is the extra level necessary?
  35.  
  36. Because further macro replacements will not be done for arguments which
  37. correspond to formal macro parameters adjacent to # or ## in the body. 
  38. stringify(JUNK) will therefore expand to "JUNK", not to "50".
  39. -----------------------------------------------------------------------------
  40. Harald Winroth      |  Computational Vision and Active Perception Laboratory,
  41. harald@bion.kth.se  |  Royal Institute of Technology, Stockholm, Sweden.
  42. -----------------------------------------------------------------------------
  43.