home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20341 comp.std.c:3440
- Newsgroups: comp.lang.c,comp.std.c
- 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
- From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
- Subject: Re: Preprocessor question
- Message-ID: <1993Jan28.083305.4285@nntpd.lkg.dec.com>
- Keywords: Preprocessor, string
- Sender: usenet@nntpd.lkg.dec.com (USENET News System)
- Reply-To: diamond@jit.dec.com (Norman Diamond)
- Organization: Digital Equipment Corporation Japan , Tokyo
- References: <1993Jan25.161425.27962@bnrmtl.bnr.ca> <C1I4r2.2FF@cmie.ernet.in>
- Date: Thu, 28 Jan 1993 08:33:05 GMT
- Lines: 37
-
- In article <C1I4r2.2FF@cmie.ernet.in> rs@cmie.ernet.in (Rajappa Iyer) writes:
- >karim@bnrmtl.bnr.ca (Karim Younes) writes:
- >>I am trying to have a #defined variable recognized by the
- >>preprocessor inside a string.
- >>#define JUNK 50
- >>static char *junk = "JUNK ways to leave your lover."
-
- Even Reiser's preprocessor didn't do that. He only did it for arguments
- of the macro being expanded, so that if the violation of K&R-1 produced
- an effect that the user didn't really want, it could be avoided by a local
- change in the macro, without affecting the rest of the program.
-
- >#define JUNK "50"
- >static char *junk = JUNK " ways to leave your lover."
-
- Yes this works, but if the user also wanted to use a numeric value of JUNK...
- As you said, this fails:
- >#define JUNK 50
- >#define STR(x) #x
- >char *junk = STR(JUNK) " ways to leave your lover."
-
- >Which kind of makes me question the utility of the `#' preprocessor operator.
-
- char *junk = STR(Fifty) " ways to leave your lover.";
- might be perfectly meaningful for some users.
-
- Although ANSI's syntax is ugly, it does provide more options than some
- alternatives would. For example, this works for the original user:
-
- #define JUNK 50
- #define STR(x) STRX(x)
- #define STRX(x) #x
- char *junk = STR(JUNK) " ways to leave your lover.";
- --
- Norman Diamond diamond@jit.dec.com
- If this were the company's opinion, I wouldn't be allowed to post it.
- Pardon me? Or do I have to commit a crime first?
-