isascii(3) macros and casts
Alejandro Colomar
alx@kernel.org
Wed Dec 11 14:27:43 GMT 2024
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.
alx@devuan:~/tmp/glibc$ cat isdigit.c
#include <ctype.h>
#include <stdio.h>
int
my_isdigit(int c)
{
unsigned char uc = c;
return isdigit(uc);
}
int
main(void)
{
printf("%d\n", isdigit((unsigned char) EOF));
printf("%d\n", my_isdigit(EOF));
}
alx@devuan:~/tmp/glibc$ cc -Wall -Wextra isdigit.c
alx@devuan:~/tmp/glibc$ ./a.out
0
0
This experiment seems to say it's ok.
Cheers,
Alex
--
<https://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20241211/77f00de5/attachment.sig>
More information about the Libc-alpha
mailing list