isascii(3) macros and casts

Florian Weimer fweimer@redhat.com
Wed Dec 11 19:36:32 GMT 2024


* Andreas Schwab:

> On Dez 11 2024, Alejandro Colomar wrote:
>
>> Hi Andreas,
>>
>> On Wed, Dec 11, 2024 at 03:03:00PM +0100, Andreas Schwab wrote:
>>> On Dez 11 2024, Alejandro Colomar wrote:
>>> 
>>> > 	inline bool
>>> > 	my_isdigit(int c)
>>> > 	{
>>> > 		unsigned char  uc = c;
>>> >
>>> > 		return isdigit(uc);
>>> 
>>> This is wrong for EOF.
>>
>> Is it?  EOF is -1, which is converted to 255, which is not a digit.
>
> That depends on the locale's charset.

At least in C11, isdigit must only return true for any of 0123456789.

| The isdigit function tests for any decimal-digit character (as defined
| in 5.2.1).

And 5.2.1 says:

| Both the basic source and basic execution character sets shall have
| the following members: […]
|
| the 10 decimal digits
|
|    0 1 2 3 4 5 6 7 8 9

It does not define the decimal-digit production, but that appears to be
an oversight.

We only support ASCII-transparent locales, so e.g. 9 cannot have the
value -1.

The table lookups for isdigit and isxdigit are unnecessary.

Thanks,
Florian



More information about the Libc-alpha mailing list