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

  1. Xref: sparky comp.lang.c:20341 comp.std.c:3440
  2. Newsgroups: comp.lang.c,comp.std.c
  3. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!udel!bogus.sura.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!ames!decwrl!pa.dec.com!engage.pko.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  4. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  5. Subject: Re: Preprocessor question
  6. Message-ID: <1993Jan28.083305.4285@nntpd.lkg.dec.com>
  7. Keywords: Preprocessor, string
  8. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  9. Reply-To: diamond@jit.dec.com (Norman Diamond)
  10. Organization: Digital Equipment Corporation Japan , Tokyo
  11. References: <1993Jan25.161425.27962@bnrmtl.bnr.ca> <C1I4r2.2FF@cmie.ernet.in>
  12. Date: Thu, 28 Jan 1993 08:33:05 GMT
  13. Lines: 37
  14.  
  15. In article <C1I4r2.2FF@cmie.ernet.in> rs@cmie.ernet.in (Rajappa Iyer) writes:
  16. >karim@bnrmtl.bnr.ca (Karim Younes) writes:
  17. >>I am trying to have a #defined variable recognized by the
  18. >>preprocessor inside a string.
  19. >>#define JUNK 50
  20. >>static char *junk = "JUNK ways to leave your lover."
  21.  
  22. Even Reiser's preprocessor didn't do that.  He only did it for arguments
  23. of the macro being expanded, so that if the violation of K&R-1 produced
  24. an effect that the user didn't really want, it could be avoided by a local
  25. change in the macro, without affecting the rest of the program.
  26.  
  27. >#define JUNK "50"
  28. >static char *junk = JUNK " ways to leave your lover."
  29.  
  30. Yes this works, but if the user also wanted to use a numeric value of JUNK...
  31. As you said, this fails:
  32. >#define JUNK    50
  33. >#define STR(x)    #x
  34. >char *junk = STR(JUNK) " ways to leave your lover."
  35.  
  36. >Which kind of makes me question the utility of the `#' preprocessor operator.
  37.  
  38. char *junk = STR(Fifty) " ways to leave your lover.";
  39. might be perfectly meaningful for some users.
  40.  
  41. Although ANSI's syntax is ugly, it does provide more options than some
  42. alternatives would.  For example, this works for the original user:
  43.  
  44. #define JUNK    50
  45. #define STR(x)    STRX(x)
  46. #define STRX(x)    #x
  47. char *junk = STR(JUNK) " ways to leave your lover.";
  48. --
  49. Norman Diamond                diamond@jit.dec.com
  50. If this were the company's opinion, I wouldn't be allowed to post it.
  51. Pardon me?  Or do I have to commit a crime first?
  52.