From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28381 invoked by alias); 8 Oct 2004 17:20:17 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 28374 invoked from network); 8 Oct 2004 17:20:17 -0000 Received: from unknown (HELO kiruna.synopsys.com) (198.182.44.80) by sourceware.org with SMTP; 8 Oct 2004 17:20:17 -0000 Received: from mother.synopsys.com (mother.synopsys.com [146.225.100.171]) by kiruna.synopsys.com (Postfix) with ESMTP id 148E2F2B0; Fri, 8 Oct 2004 10:19:59 -0700 (PDT) Received: from piper.synopsys.com (localhost [127.0.0.1]) by mother.synopsys.com (8.9.1/8.9.1) with ESMTP id KAA10049; Fri, 8 Oct 2004 10:20:16 -0700 (PDT) Received: (from jbuck@localhost) by piper.synopsys.com (8.11.6/8.11.6) id i98HKEI02399; Fri, 8 Oct 2004 10:20:14 -0700 X-Authentication-Warning: piper.synopsys.com: jbuck set sender to Joe.Buck@synopsys.com using -f Date: Fri, 08 Oct 2004 18:22:00 -0000 From: Joe Buck To: Dave Korn Cc: "'Nick Ing-Simmons'" , jamie@shareable.org, gcc@gcc.gnu.org, "'Morten Welinder'" Subject: Re: signed vs unsigned pointer warning Message-ID: <20041008102014.A2364@synopsys.com> References: <20041008100853.A2207@synopsys.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: ; from dk@artimi.com on Fri, Oct 08, 2004 at 06:12:09PM +0100 X-SW-Source: 2004-10/txt/msg00364.txt.bz2 I wrote: > > Here's a bug fix: > > > > table_lookup[1U+(unsigned)(c)] > > > > Now EOF goes into slot 0. On Fri, Oct 08, 2004 at 06:12:09PM +0100, Dave Korn wrote: > Hmm, but only by virtue of integer maths overflow. Wouldn't it be better > to just leave out the cast in this case and do the sum in signed math? No. The C standard guarantees that unsigned arithmetic obeys the rules of arithmetic modulo 2**N, where N is the number of bits. The overflow is well-defined and is required to yield zero. Signed math would mishandle the original case, where the original argument was a signed char with 8th bit set.