From owner-freebsd-arch Mon Nov 29 14: 8:16 1999 Delivered-To: freebsd-arch@freebsd.org Received: from ns1.yes.no (ns1.yes.no [195.204.136.10]) by hub.freebsd.org (Postfix) with ESMTP id 1BFF414FAF for ; Mon, 29 Nov 1999 14:08:13 -0800 (PST) (envelope-from eivind@bitbox.follo.net) Received: from bitbox.follo.net (bitbox.follo.net [195.204.143.218]) by ns1.yes.no (8.9.3/8.9.3) with ESMTP id XAA24491 for ; Mon, 29 Nov 1999 23:08:12 +0100 (CET) Received: (from eivind@localhost) by bitbox.follo.net (8.8.8/8.8.6) id XAA66477 for freebsd-arch@freebsd.org; Mon, 29 Nov 1999 23:08:12 +0100 (MET) Received: from knight.cons.org (knight.cons.org [194.233.237.195]) by hub.freebsd.org (Postfix) with ESMTP id 79D6714FAF for ; Mon, 29 Nov 1999 14:07:30 -0800 (PST) (envelope-from cracauer@knight.cons.org) Received: (from cracauer@localhost) by knight.cons.org (8.9.3/8.9.3) id XAA10798 for arch@FreeBSD.ORG; Mon, 29 Nov 1999 23:07:25 +0100 (CET) Date: Mon, 29 Nov 1999 23:07:25 +0100 From: Martin Cracauer To: arch@freebsd.org Subject: Re: What to do about "subscript has type `char'" warnings? Message-ID: <19991129230725.B10767@cons.org> References: <19991129201610.A9998@cons.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.1i In-Reply-To: <19991129201610.A9998@cons.org>; from Martin Cracauer on Mon, Nov 29, 1999 at 08:16:11PM +0100 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 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 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