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

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!hubcap!ncrcae!ncrhub2!ncrgw2!psinntp!heimdall!thor!scjones
  2. From: scjones@thor.sdrc.com (Larry Jones)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Preprocessor question
  5. Keywords: Preprocessor, string
  6. Message-ID: <566@heimdall.sdrc.com>
  7. Date: 26 Jan 93 16:02:28 GMT
  8. References: <1993Jan25.161425.27962@bnrmtl.bnr.ca>
  9. Sender: news@heimdall.sdrc.com
  10. Lines: 30
  11.  
  12. In article <1993Jan25.161425.27962@bnrmtl.bnr.ca>, karim@bnrmtl.bnr.ca (Karim Younes) writes:
  13. > I am trying to have a #defined variable recognized by the
  14. > preprocessor inside a string. In other words, I want to
  15. > do something like this:
  16. > #define JUNK 50
  17. > static char *junk = "JUNK ways to leave your lover."
  18.  
  19. If you have an ANSI/ISO Standard C compiler, you can use the new
  20. stringizing operator and string concatenation to get what you want:
  21.  
  22. #define stringsub(x)    string(x)
  23. #define string(x)    #x
  24.  
  25. #define JUNK 50
  26. static char *junk = stringsub(JUNK) " ways to leave your lover.";
  27.  
  28. If you have an older compiler that doesn't support stringizing or
  29. concatenation, you might be able to get away with something like:
  30.  
  31. #define stringsub(x)    "x"
  32.  
  33. #define JUNK 50
  34. static char *junk = stringsub(JUNK ways to leave your lover.);
  35.  
  36. but I wouldn't count on it.
  37. ----
  38. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  39. larry.jones@sdrc.com
  40. Sheesh.  Who can fathom the feminine mind? -- Calvin
  41.