This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: egcs, warning patch for missing initializers in xsys-protos.h

 > From: Richard Henderson <>
 > 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~


	IMHO, you can't safely cast ctype function arguments in the
ctype macros.  This was partially discussed last February starting with:  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

	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 R. Ghazi			Engagement Manager / Project Services		Icon CMT Corp.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]