Patch for isdigit/isalpha/etc. macro arguments

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Patch for isdigit/isalpha/etc. macro arguments

DJ Delorie-2

Daniel Jacobowitz <[hidden email]> writes:
> I think we should decide whether this constitutes a Real Problem,
> and whether we care about it, before we do this.  It seems that
> passing a char to isfoo is not portable, although I could not tell for
> sure from the discussion whether ISO C requires it to work.

ISO C requires you to pass 0..255 or EOF, nothing else, to is*().

If the char might be signed, one must either cast it to unsigned char
or mask it with 0xff before using it as a subscript, else one risks a
negative subscript.  Negative values aren't guaranteed to work with
is*(), although some implementations put a second copy of the ctype
data array in front of the normal one to accomodate values in the
range -128..-1.  I suspect this is mostly to keep uninformed
programmers from bothering the mailing lists with complaints about
is*() not working when really it's the programmer's fault.
Reply | Threaded
Open this post in threaded view
|

Re: Patch for isdigit/isalpha/etc. macro arguments

Eli Zaretskii
In reply to this post by Steve Ellcey
> Date: Tue, 10 Apr 2007 14:16:16 -0700 (PDT)
> From: Steve Ellcey <[hidden email]>
>
> Well, this discussion was very interesting but I am not sure it led
> anywhere.  If casting to '(int)' is unacceptable, double casting to
> '(int) (unsigned char)' is probably even less acceptable so I would like
> to check in the following patch that turns off the warnings so I can
> build on HPPA HP-UX.
>
> Tested by building on HPPA HP-UX.
>
> OK to checkin?

Fine with me, thanks.
12