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

  1. Path: sparky!uunet!europa.eng.gtefsd.com!emory!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. Message-ID: <589@heimdall.sdrc.com>
  6. Date: 28 Jan 93 14:59:46 GMT
  7. References: <1k44lqINNjr3@rs2.hrz.th-darmstadt.de> <1099@quirm.terminus.ericsson.se>
  8. Sender: news@heimdall.sdrc.com
  9. Lines: 26
  10.  
  11. In article <1099@quirm.terminus.ericsson.se>, srl@terminus.ericsson.se (Steve Langstaff) writes:
  12. > In article 1k44lqINNjr3@rs2.hrz.th-darmstadt.de, misar@rbg.informatik.th-darmstadt.de (Walter Misar) writes:
  13. > : #define stringify(x) #x
  14. > : #define str_exp(x) stringify(x)        /* this extra level IS necessary */
  15. > : static char *junk = str_exp(JUNK) "ways ....";
  16. > Why is the extra level necessary?
  17.  
  18. Because stringify produces a string containing the actual argument
  19. *without* expanding any macros it contains; if you want the macros
  20. expanded, then you have to use another level of macro.  This allows you
  21. to get either the expanded value like you want above, or the unexpanded
  22. value like you want for doing things like:
  23.  
  24.     #define debug_val(i) printf(stringify(i) " = %d\n", i)
  25.     ...
  26.     debug_val(JUNK);
  27.  
  28. to get the output:
  29.  
  30.     JUNK = 50
  31. ----
  32. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  33. larry.jones@sdrc.com
  34. These pictures will remind us of more than we want to remember.
  35. -- Calvin's Mom
  36.