Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Casting ctype lookups
On Mon, 12 Nov 2012 19:58:05 +0000
David Laight <david%l8s.co.uk@localhost> wrote:
> > I see the point about code that passes a signed char being
> > incorrect. However, the standard seems to say that isalpha etc. are
> > required to be functions that take an int, and may also be macros.
> > So it seems that code that is written with an unsigned char should
> > compile without warnings.
>
> Passing an 'unsigned char' is fine, and not warned about.
$ gcc -o t -funsigned-char -Wall -Werror t.c
cc1: warnings being treated as errors
t.c: In function 'func':
t.c:6:3: error: array subscript has type 'char'
But it doesn't happen if I declare the string unsigned char in the
source file. Seems like a gcc wart.
> I suspect that the gcc warning is there specifically for the ctype
> functions.
I did a test that suggests that it is any array index that uses char.
> > This all seems quite difficult; the notion of a int carrying either
> > a char or EOF makes it likely to have errors from type promotion.
>
> You'll find that is the standard return value from getc() etc.
Yes, using the return from getc is a different animal because it does
return int, not char of any stripe.
How come all my questions seem to result in "numAnsers >=
numRespondents." :-)
--
D'Arcy J.M. Cain <darcy%NetBSD.org@localhost>
http://www.NetBSD.org/ IM:darcy%Vex.Net@localhost
Home |
Main Index |
Thread Index |
Old Index