This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][RFC] Avoid table lookup in isascii, isxdigit.
- From: Rich Felker <dalias at aerifal dot cx>
- To: Paul Eggert <eggert at cs dot ucla dot edu>
- Cc: OndÅej BÃlka <neleai at seznam dot cz>, libc-alpha at sourceware dot org
- Date: Sat, 13 Apr 2013 12:18:18 -0400
- Subject: Re: [PATCH][RFC] Avoid table lookup in isascii, isxdigit.
- References: <20130409115706 dot GA7587 at domone dot kolej dot mff dot cuni dot cz> <20130412204241 dot GK20323 at brightrain dot aerifal dot cx> <51687F17 dot 3070806 at cs dot ucla dot edu> <20130413064316 dot GL20323 at brightrain dot aerifal dot cx> <51697F4B dot 4050307 at cs dot ucla dot edu>
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