From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6186 invoked by alias); 23 Sep 2004 16:31:58 -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 5990 invoked from network); 23 Sep 2004 16:31:56 -0000 Received: from unknown (HELO NUTMEG.CAM.ARTIMI.COM) (217.40.111.177) by sourceware.org with SMTP; 23 Sep 2004 16:31:56 -0000 Received: from mace ([192.168.1.25]) by NUTMEG.CAM.ARTIMI.COM with Microsoft SMTPSVC(6.0.3790.0); Thu, 23 Sep 2004 17:31:54 +0100 From: "Dave Korn" To: "'Joe Buck'" Cc: "'Andreas Schwab'" , "'Morten Welinder'" , Subject: RE: signed vs unsigned pointer warning Date: Thu, 23 Sep 2004 19:38:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <20040923091118.A2943@synopsys.com> Message-ID: X-OriginalArrivalTime: 23 Sep 2004 16:31:54.0298 (UTC) FILETIME=[D61CB1A0:01C4A18A] X-SW-Source: 2004-09/txt/msg01349.txt.bz2 > -----Original Message----- > From: Joe Buck [mailto:Joe.Buck@synopsys.COM] > Sent: 23 September 2004 17:11 > On Thu, Sep 23, 2004 at 12:35:22PM +0100, Dave Korn wrote: > > > "Dave Korn" writes: > > > > > > > Which I don't think you can, since you can't store > negative numbers > > > > in an unsigned type. > > > > > > Actually you can, due to the modulo behaviour of unsigned > integers. > > > > > > Andreas. > > > > Well, yes, it is physically possible, but it's a kind of > type-punning, it > > defies the aliasing rules, and we get into some very deeply > > language-lawyerly issues here, but it's not a valid > representation IIUIC and > > therefore invokes undefined behaviour in many circumstances. > > The C aliasing rules specifically bless accessing ints as > unsigneds, and, > more generally, punning accesses between any type and the > unsigned version > of that type. Ya learn something new every day :) Actually, come to think of it, I stumbled across that myself just a few weeks back, when I was trying to work round the _restrict_ bug (in a block of code that was copying some memory to some registers) by defining one pointer as an int and one pointer as a long (both actually being 32 bit ints), and I had tried to use the signed/unsigned distinction to get it to work, but it didn't until I actually used different underlying types. Anyway, it's all wandering a bit far enough from the original point now, which is that a warning would be a good idea, and I'm convinced enough by that line of argument without any reference to the finer details of buggy ctype implementations anyway! cheers, DaveK -- Can't think of a witty .sigline today....