home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Newsgroups: comp.lang.c
- Subject: Re: printf question
- Message-ID: <1992Sep2.124131.13678@klaava.Helsinki.FI>
- Date: 2 Sep 92 12:41:31 GMT
- References: <1992Sep01.214725.6334@ima.isc.com> <18260@acorn.co.uk>
- Organization: University of Helsinki
- Lines: 27
-
- jcoxhead@acorn.co.uk (Jonathan Coxhead) writes:
- > The C preprocessor has no way to evaluate-and-stringise a constant
- > expression.
- >
- >but it does!
- >
- >[ C code deleted, but it's almost the same as the code below, but with
- > WIDTH defined as 8 only --liw]
-
- Input to preprocessor:
- #define STR_(s) #s
- #define STR(s) STR_ (s)
- #define WIDTH 8+2
- printf ("%" STR (WIDTH) "x", n);
-
- Output from preprocessor (with empty lines removed):
- # 1 "foo.c"
- printf ("%" "8+2" "x", n);
-
- Nope, the C preprocessor does not evaluate 8+2 into 10.
-
- (Not that I'm not saying that it should, since it clearly shouldn't,
- especially in this case, 'cause it can't know whether 8+2 or 10 is
- wanted.)
-
- --
- Lars.Wirzenius@helsinki.fi
-