This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: egcs, warning patch for missing initializers in xsys-protos.h
- To: egcs-patches at cygnus dot com, rth at cygnus dot com
- Subject: Re: egcs, warning patch for missing initializers in xsys-protos.h
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Sat, 19 Sep 1998 09:01:55 -0400 (EDT)
> From: Richard Henderson <rth@cygnus.com>
>
> On Wed, Sep 16, 1998 at 10:42:24AM -0400, Kaveh R. Ghazi wrote:
> > - if (!ISALNUM (*ptr))
> > + if (!ISALNUM ((unsigned char)*ptr))
>
> If this needs doing, why isn't it done in ISALNUM?
>
> In any case, isalnum normally takes an int, since isalnum(EOF)
> is defined.
> r~
Richard,
IMHO, you can't safely cast ctype function arguments in the
ctype macros. This was partially discussed last February starting with:
http://www.cygnus.com/ml/egcs/1998-Feb/0643.html. It became clear, in
that discussion, that casting to int was bad. The warning is pointing
out something valid, the fact that char is often signed and when you
evaluate character values > 127, you get negative results. Ctype macros
are often defined as lookups in an array, thus the negative index is
bogus.
However, I wasn't satisfied with the direction of that
discussion which seemed to endorse casting >>in the macro definition<<
to unsigned char, because as you note above it fails to properly
handle EOF.
The only solution appears to be fixing the source code at the
*site* of each call. If its already an int, no fix is needed. If the
type is a char, you can safely cast it to unsigned char because
supposedly you are already assuming that EOF is not in play.
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Icon CMT Corp.