This is the mail archive of the gcc@gcc.gnu.org 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, casting the argument of eg isalpha to an int...


On Fri, 13 February 1998, 15:08:23, ghazi@caip.rutgers.edu wrote:

 > 	I'm getting a lot of warnings building egcs of the form
 > "subscript has type `char'".  These seem to occur because the ctype
 > is* functions (eg isalpha) are used and passed a `char' type.  These
 > functions are prototyped in ctype.h as taking an int parameter but
 > they are often defined as macros which do a lookup in an array like
 > this:
 > 
 >  > #define isalpha(__c) (__ctype2[__c]&(_A))
 > 
 > So this appears to be the source of the warning.
 > 
 > 
 > 	Now system.h has custom versions of the ctype macros which
 > look like this:
 > 
 >  > #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
 > 
 > I'm thinking of changing them to this:
 > 
 >  > #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (((int)(c))))
 > 
 > This would seem to avoid the warning.
 > 
 > 	Is this solution correct from a technical standpoint?
 > 

This yields wrong results for e.g. bloody german umlauts with the
high bit set:

int my_isalpha (int c)
{
	printf ("%d, '%c'\n", c, c);
	return 0;
}

main ()
{
	my_isalpha ((int) 'A');
	my_isalpha ((int) 'ä');
}

gives:

65, 'A'
-28, 'ä'

the following cast sequence would be better:

	my_isalpha ((int) ((unsigned char) 'A'));
	my_isalpha ((int) ((unsigned char) 'ä'));

This gives:

65, 'A'
228, 'ä'

Manfred


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