Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Nov 1999 11:30:46 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Martin Cracauer <cracauer@cons.org>
Cc:        arch@freebsd.org
Subject:   Re: What to do about "subscript has type `char'" warnings?
Message-ID:  <199911291930.LAA08250@apollo.backplane.com>
References:   <19991129201610.A9998@cons.org>

next in thread | previous in thread | raw e-mail | index | archive | help
:Newest compiler now produces a lot of "subscript has type `char'"
:warnings for sh (its syntax table).
:
:I would change direct appearences of 
:  char bla;
:  string[bla];
:to 
:  int bla;
:  string[bla];
:which IMHO is consistent with ANSI C and its int and char properties. 
:
:A different matter is an index that is a followed pointer to a char;
:  char *s = syntax[2];
:  string[*s];
:
:I could either 
:a) use an additional int variable, which causes some
:   overhead, of course
:b) or cast  
:  char *s = syntax[2];
:  string[(int)*s];
:
:I tend to cast for the second case, although it's a little
:inconsistent with the fix for the direct case. Opinions?
:
:Martin
:-- 
:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
:  Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536

    This warning exists because many programmers do not realize
    that the signess of 'char' is platform dependant.  'char'
    defaults to being signed on x86 and unsigned on MIPS, for
    example.  People often make the mistake of trying to
    index an array with 'char'.

    The correct solution is to cast it properly.  If casting
    a char to an int is not correct due to a possible signed
    result, then you need to cast the char to an unsigned char
    first.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911291930.LAA08250>