towards a faster isdigit()
Andrew Koenig
ark at alice.att.com
Thu May 9 02:18:49 AEST 1991
In article <1991May8.030515.7004 at twinsun.com> eggert at twinsun.com (Paul Eggert) writes:
> Why not use the following implementation instead?
> #define isdigit(c) ((unsigned)((c)-'0') < 10)
> This needs just a subtraction followed by a comparison. It's faster on
> all the systems I've tried it on, and is strictly conforming ANSI C.
This is surely an implementation issue.
However, it does suggest an interesting puzzle: can you find a
character set that meets the ANSI C constraints (in particular,
the one that says that all digits are contiguous in the character
set) for which this macro will not work? (Yes, I think there is one)
--
--Andrew Koenig
ark at europa.att.com
More information about the Comp.lang.c
mailing list