This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][RFC] Avoid table lookup in isascii, isxdigit.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]