home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!mcsun!sun4nl!and!jos
- From: jos@and.nl (Jos Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: printf question
- Message-ID: <3361@dozo.and.nl>
- Date: 30 Aug 92 14:25:57 GMT
- References: <kimcm.714943581@login.dkuug.dk> <1226@pascal.einstein.eds.com> <RICHARD.92Aug30153124@CLYDE.ttt.kth.se>
- Organization: AND Software BV Rotterdam
- Lines: 27
-
- In article <RICHARD.92Aug30153124@CLYDE.ttt.kth.se> RICHARD@CLYDE.ttt.kth.se writes:
- |In article <kimcm.714943581@login.dkuug.dk> kimcm@login.dkuug.dk (Kim Chr. Madsen) writes:
- || #define HDPI "4" /* Hex Digits Per Int */
- ||
- || printf( "%0" HDPI "x\n", address );
- ||
- || And if you have read this far, you surely won't mind one more irrelevant
- || remark ;-) Using this syntax on the original problem will save you some
- || time because the format is evaluated at compile time instead of run time.
- |
- |Huh????? Since when is the format evaluated at compile time? I've never
- |seen that done!
-
- The contents of the format string isn't evaluated at compile time but,
- in this case, the pre-processor concatenates the constant strings after
- macro replacement. The evaluation goes like this:
-
- 1: printf( "%0" HDPI "x\n", address );
- 2: printf( "%0" "4" "x\n", address );
- 3: printf( "%04x\n", address );
-
- And that was exactly what the original poster had in mind; all done during
- compile time ...
-
- kind regards,
-
- Jos aka jos@and.nl
-