Date: Mon, 29 Nov 1999 23:07:25 +0100 From: Martin Cracauer <cracauer@cons.org> To: arch@freebsd.org Subject: Re: What to do about "subscript has type `char'" warnings? Message-ID: <19991129230725.B10767@cons.org> In-Reply-To: <19991129201610.A9998@cons.org>; from Martin Cracauer on Mon, Nov 29, 1999 at 08:16:11PM %2B0100 References: <19991129201610.A9998@cons.org>
next in thread | previous in thread | raw e-mail | index | archive | help
I'd like to point out that the code in question is 100% correct, because the indexing is guaranteed to be < 128. I only want to kill the warning, but in the least obscure way and not killing other warnings that may come up in future. In <19991129201610.A9998@cons.org>, Martin Cracauer wrote: > 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 > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-arch" in the body of the message -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/ Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536 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?19991129230725.B10767>