char array subscript in ctype

Peter Naulls peter at
Sun Dec 30 22:27:33 PST 2001

In message <3C2FB10F.7040105 at>
          Ian Jeffray <ian at> wrote:

> Peter Naulls wrote:
> > I'm not sure that's a valid argument.  isspace and friends are almost
> > always used in the context of unqualified chars (unsigned on ARM, signed
> > on x86).   Futhermore, the specification for these functions says that
> > the integer passed is interpreted as an unsigned char (or EOF).  The
> > cast to unsigned int ensures this.
> Not really... the cast "ensures" that you _don't_ know when you've
> written some crap code.

No, I'm just quoting common usage and what the defintion of these
functions say.

> > That aside, the real point is that the library headers cause a warning,
> > which they really shouldn't.  Although Norcroft's defintions are
> > similar, the compiler itself doesn't issue this warning, which is why
> > it's not seen.  glibc sets up the functions quite differently so it
> > doesn't occur with that.
> You're saying that a compiler which doesn't issue a warning about an
> incorrect type is preferable to one which does?  That doesn't sound very
> sensible to me.

I'm sure you're quite aware I haven't said that.

> The warning only occurrs in the case where you've supplied a bad
> type to the function.  It goes away if you pass an appropriate type.
> This is what C functions do.  I hardly think we should be changing the
> way the language works just to remove some warnings you don't happen
> to like.

Actually, the functions accept ints.   I'm also quite sure you're aware
I'm not advocating changing the language.   My intent here, if anything
is to enforce the meaning of these functions.   The exact way we go
about that is open to debate, and my suggestion remains only that.

> Extending your argument to the limit, you may as well put a cast in
> to every single function prototype in every .h to avoid warnings.
> I'm sure you'll agree that's rubbish.  :-)

Of course.  But again, I'm sure you're aware I'm not advocating that.

 Peter Naulls - peter at
 RISC OS Projects Initiative  -
 Java for RISC OS and ARM     -
 Debian Linux on RiscPCs      -

More information about the gcc mailing list