From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5653 invoked by alias); 21 Oct 2002 13:48:43 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 5646 invoked from network); 21 Oct 2002 13:48:41 -0000 Received: from unknown (HELO wh2-19.st.uni-magdeburg.de) (141.44.162.19) by sources.redhat.com with SMTP; 21 Oct 2002 13:48:41 -0000 Received: by wh2-19.st.uni-magdeburg.de (Postfix, from userid 1000) id F278890F60; Mon, 21 Oct 2002 15:49:01 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15796.1484.410694.966062@wh2-19.st.uni-magdeburg.de> Date: Mon, 21 Oct 2002 06:48:00 -0000 From: "Claudio Bley" To: Florian Weimer Cc: "Joshua Nye" , "Steve Dondley" , Subject: Re: Avoiding "assignment from incompatible pointer type" warning In-Reply-To: <87hefguj01.fsf@deneb.enyo.de> References: <000d01c272d5$85368b20$0100a8c0@windows9q3yn19> <87adlidm9l.fsf@deneb.enyo.de> <001801c27478$0ee5e480$c800a8c0@pdc1.boxcarmedia.com> <87r8ekumlc.fsf@deneb.enyo.de> <15795.58223.521979.895246@wh2-19.st.uni-magdeburg.de> <87hefguj01.fsf@deneb.enyo.de> X-SW-Source: 2002-10/txt/msg00242.txt.bz2 >>>>> "Florian" == Florian Weimer writes: Florian> "Claudio Bley" writes: >> >> What do you consider legal and why wouldn't it be? >> Florian> Casting a pointer from float to int can result in Florian> undefined behavior on some implementations. >> I can't see why. Can you elaborate on that? Florian> Well, it's all in the standard, although it's a bit Florian> scattered. >> I mean, casting on the machine code level does just nothing - >> it's just "syntactic sugar" to convince the compiler to be >> quiet. Florian> It's not. In C, pointers are NOT machine addresses. Florian> Pointers are an abstract concept, and often, something Florian> which would work if they were machine addresses, fails Florian> miserably. For example, even if two pointers compare Florian> equal (because they point to the same object), it's Florian> possible that an operation on one of the two is Florian> undefined, while it is defined for the other one. >> I think casting from one pointer type to another does no harm >> at all. Am I wrong? Florian> Yes, you are, I'm afraid. I'm afraid too! ;-) Really. I'm using C for quite a while now, read a few books but I never realized that. I was thinking that a cast just meant "pretend these bits have a different type, and treat them accordingly". Also, as Mathew Moore mentioned, I was not thinking about alignment issues. Regards. -- Claudio Bley ASCII ribbon campaign (") Debian GNU/Linux advocate - against HTML email X http://www.cs.uni-magdeburg.de/~bley/ & vCards / \