home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!hubcap!ncrcae!ncrhub2!ncrgw2!psinntp!heimdall!thor!scjones
- From: scjones@thor.sdrc.com (Larry Jones)
- Newsgroups: comp.lang.c
- Subject: Re: Preprocessor question
- Keywords: Preprocessor, string
- Message-ID: <566@heimdall.sdrc.com>
- Date: 26 Jan 93 16:02:28 GMT
- References: <1993Jan25.161425.27962@bnrmtl.bnr.ca>
- Sender: news@heimdall.sdrc.com
- Lines: 30
-
- In article <1993Jan25.161425.27962@bnrmtl.bnr.ca>, karim@bnrmtl.bnr.ca (Karim Younes) writes:
- > I am trying to have a #defined variable recognized by the
- > preprocessor inside a string. In other words, I want to
- > do something like this:
- >
- > #define JUNK 50
- > static char *junk = "JUNK ways to leave your lover."
-
- If you have an ANSI/ISO Standard C compiler, you can use the new
- stringizing operator and string concatenation to get what you want:
-
- #define stringsub(x) string(x)
- #define string(x) #x
-
- #define JUNK 50
- static char *junk = stringsub(JUNK) " ways to leave your lover.";
-
- If you have an older compiler that doesn't support stringizing or
- concatenation, you might be able to get away with something like:
-
- #define stringsub(x) "x"
-
- #define JUNK 50
- static char *junk = stringsub(JUNK ways to leave your lover.);
-
- but I wouldn't count on it.
- ----
- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070
- larry.jones@sdrc.com
- Sheesh. Who can fathom the feminine mind? -- Calvin
-