home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!uwm.edu!ogicse!das-news.harvard.edu!spdcc!dirtydog.ima.isc.com!karl
- From: karl@ima.isc.com (Karl Heuer)
- Newsgroups: comp.lang.c
- Subject: Re: printf question
- Message-ID: <1992Sep01.214725.6334@ima.isc.com>
- Date: 1 Sep 92 21:47:25 GMT
- Article-I.D.: ima.1992Sep01.214725.6334
- References: <1226@pascal.einstein.eds.com> <RICHARD.92Aug30153124@CLYDE.ttt.kth.se> <3361@dozo.and.nl>
- Sender: usenet@ima.isc.com (news)
- Organization: Interactive Systems, Cambridge, MA 02138-5302
- Lines: 16
-
- In article <kimcm.714943581@login.dkuug.dk> kimcm@login.dkuug.dk (Kim Chr. Madsen) writes:
- >Using this syntax on the original problem will save you some time because the
- >format is evaluated at compile time instead of run time.
-
- On the other hand, when the printf interpreter encounters the format "%04x",
- it has to convert the string "4" into the integer value 4; whereas with "%0*x"
- it can just pull the value out of the argument list. I seem to recall hearing
- that somebody actually found "%0*x" to be faster. (A test on my system just
- now indicates that it may be 1/3 of a percent faster.)
-
- Of course, this is not likely to be a bottleneck in any case. I would use "*"
- for portability reasons (Classic C doesn't have string pasting), and because
- it avoids having to hardcode the string form of the magic constant. (The C
- preprocessor has no way to evaluate-and-stringize a constant expression.)
-
- Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
-