home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20266 comp.std.c:3430
- Newsgroups: comp.lang.c,comp.std.c
- Path: sparky!uunet!sangam!cmie!rs
- From: rs@cmie.ernet.in (Rajappa Iyer)
- Subject: Re: Preprocessor question
- Message-ID: <C1I4r2.2FF@cmie.ernet.in>
- Keywords: Preprocessor, string
- Organization: Centre for Monitoring Indian Economy, Bombay
- References: <1993Jan25.161425.27962@bnrmtl.bnr.ca>
- Date: Wed, 27 Jan 1993 07:28:14 GMT
- Lines: 35
-
- 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."
-
- The only ANSI way I can think of doing it is (yecch!):
-
- #define JUNK "50"
- static char *junk = JUNK " ways to leave your lover."
-
- Interestingly, I tried the following with gcc 2.2.2:
-
- #define JUNK 50
- #define STR(x) #x
-
- char *junk = STR(JUNK) " ways to leave your lover."
-
- junk expands to "JUNK ways to leave your lover." Which kind of
- makes me question the utility of the `#' preprocessor operator.
- K&R 2 says that "... replacement token sequence is preceded by #,
- string quotes (") are placed around the corresponding parameter
- and then both the # and the parameter identifier are replaced by
- the quoted argument."
-
- In other words, in the above example `x' is replaced by `JUNK'
- and quoted---`JUNK' is not expanded. Is this indeed the correct
- behavior? If it is, I really think it severely restricts the
- utility of the `#' operator. Any comments, anyone?
- --
- Rajappa Iyer rs@cmie.ernet.in (Preferred)
- riyer@shakti.ncst.ernet.in
-