This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: egcs, casting the argument of eg isalpha to an int...
- To: ghazi at caip dot rutgers dot edu
- Subject: Re: egcs, casting the argument of eg isalpha to an int...
- From: Manfred Hollstein <manfred at s-direktnet dot de>
- Date: Sat, 14 Feb 1998 12:10:21 +0100
- Cc: egcs at cygnus dot com
- References: <199802132008.PAA12868@caip.rutgers.edu>
- Reply-To: Manfred Hollstein <manfred at s-direktnet dot de>
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