isascii(3) macros and casts

Paul Eggert eggert@cs.ucla.edu
Wed Dec 11 20:38:21 GMT 2024


On 2024-12-11 11:36, Florian Weimer wrote:
> The table lookups for isdigit and isxdigit are unnecessary.

Thanks for mentioning this - I didn't know it.

Should glibc optimize isdigit into a single subtract + compare at the 
machine level? Something like the following, say?

   #define isdigit(x) ((int) {x} - '0' <= 9u)

(The "(int) {x}" avoids problems that would be caused by casting x.)

This would be significantly more efficient than the current implementation.


Also, portable code should beware that mingw and MSVC do not conform to 
this part of the C standard: in some locales isdigit returns nonzero for 
arguments that are not ASCII digits, e.g., superscript two (0xB2) in 
code page 1252.

I added a note to the Gnulib documentation about this:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=9780a7b22b53b3785a1e3bca848a8d90bd2e977e


More information about the Libc-alpha mailing list