Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Casting ctype lookups



On Wed, 14 Nov 2012 22:45:50 +0000
David Laight <david%l8s.co.uk@localhost> wrote:
> > $ gcc -Wall -Werror -o t t.c && ./t
> > cc1: warnings being treated as errors
> > t.c: In function 'func':
> > t.c:5:3: error: array subscript has type 'char'
> > $ gcc -Wall -Werror -D_CTYPE_NOINLINE -o t t.c && ./t
> > TEST STRING
> > 
> > With my proposed change the function and the macro both act the
> > same.
> 
> and your program dumps core because it is invalid.
> 
> If your code is in EBCDIC (not ASCII) then "Test string" is (I think):
> { 0xe3, 0x85, 0xa2, 0xa3, 0x40, 0xa2, 0xa3, 0x99, 0x89, 0x95, 0x87,
> 0 } and you keep passing invalid values to toupper() - with undefined
> results (which is allowed to include 'format the hard drive').

OK...

$ gcc -funsigned-char -Wall -Werror -o t t.c && ./t

Does the same thing.  The function version still works.  It may be that
gcc is the problem, at least in this case, but gcc is what we provide.

$ cat t.c
#include <stdio.h>
int main(void)
{
  char c = '\x90';
  signed char s = '\x90';
  unsigned char u = '\x90';
  
  printf("%08x %08x %08x\n", c, s, u);
  return 0;
} 
$ gcc -Wall -Werror -o t t.c && ./t
ffffff90 ffffff90 00000090
$ gcc -funsigned-char -Wall -Werror -o t t.c && ./t
00000090 ffffff90 00000090

So the flag works.  Why the error then?

I wonder who ever thought that signed char ever made any sense.  There
are no negative characters.

-- 
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