home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.eng.gtefsd.com!emory!gatech!hubcap!ncrcae!ncrhub2!ncrgw2!psinntp!heimdall!thor!scjones
- From: scjones@thor.sdrc.com (Larry Jones)
- Newsgroups: comp.lang.c
- Subject: Re: Preprocessor question
- Message-ID: <589@heimdall.sdrc.com>
- Date: 28 Jan 93 14:59:46 GMT
- References: <1k44lqINNjr3@rs2.hrz.th-darmstadt.de> <1099@quirm.terminus.ericsson.se>
- Sender: news@heimdall.sdrc.com
- Lines: 26
-
- In article <1099@quirm.terminus.ericsson.se>, srl@terminus.ericsson.se (Steve Langstaff) writes:
- > In article 1k44lqINNjr3@rs2.hrz.th-darmstadt.de, misar@rbg.informatik.th-darmstadt.de (Walter Misar) writes:
- > : #define stringify(x) #x
- > : #define str_exp(x) stringify(x) /* this extra level IS necessary */
- > : static char *junk = str_exp(JUNK) "ways ....";
- >
- > Why is the extra level necessary?
-
- Because stringify produces a string containing the actual argument
- *without* expanding any macros it contains; if you want the macros
- expanded, then you have to use another level of macro. This allows you
- to get either the expanded value like you want above, or the unexpanded
- value like you want for doing things like:
-
- #define debug_val(i) printf(stringify(i) " = %d\n", i)
- ...
- debug_val(JUNK);
-
- to get the output:
-
- JUNK = 50
- ----
- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070
- larry.jones@sdrc.com
- These pictures will remind us of more than we want to remember.
- -- Calvin's Mom
-