[PATCH][RFC] Avoid table lookup in isascii, isxdigit.
Rich Felker
dalias@aerifal.cx
Sun Apr 14 00:47:00 GMT 2013
On Sat, Apr 13, 2013 at 08:52:43AM -0700, Paul Eggert wrote:
> On 04/12/2013 11:43 PM, Rich Felker wrote:
> > Then make it ((unsigned)(int)(c)-'0'<10).
>
> On further thought, that's dubious too.
> An implementation is required to diagnose a call
> like 'isdigit ("")' but the above implementation
> wouldn't necessarily do that.
Are you sure about this requirement? There are all sorts of things
that can "go wrong" with function-like macros used to implement
functions, but the standard allows them. For instance:
isdigit(*(int[2]){'0','1'})
will result in an error at the preprocessor level, no matter what
macro definition you use, despite it being a valid function call.
If you really do want the constraint violation, it can be done in C99
as:
#define isdigit(c) ((unsigned)(int){(c)}-'0'<10)
but I'm not convinced the standard requires it. Anyone have a good
reference for that?
Rich
More information about the Libc-alpha
mailing list