From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26059 invoked by alias); 21 Oct 2002 13:07:23 -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 26049 invoked from network); 21 Oct 2002 13:07:21 -0000 Received: from unknown (HELO bclcl1.im.battelle.org) (131.167.1.2) by sources.redhat.com with SMTP; 21 Oct 2002 13:07:21 -0000 Received: from ns-bco-scn1.im.battelle.org ([131.167.1.122]) by BCLCL1 (PMDF V5.1-10 #U2779) with SMTP id <01KNX6FJHX0495NJBE@BCLCL1> for gcc-help@gcc.gnu.org; Mon, 21 Oct 2002 09:07:32 EDT Received: from 131.167.1.91 by ns-bco-scn1.im.battelle.org (InterScan E-Mail VirusWall NT); Mon, 21 Oct 2002 09:06:51 -0400 Received: by ws-bco-mse1.milky-way.battelle.org with Internet Mail Service (5.5.2655.55) id ; Mon, 21 Oct 2002 09:06:52 -0400 Date: Mon, 21 Oct 2002 06:07:00 -0000 From: "Moore, Mathew L" Subject: RE: Avoiding "assignment from incompatible pointer type" warning To: 'Claudio Bley' , Florian Weimer Cc: Joshua Nye , Steve Dondley , gcc-help@gcc.gnu.org Message-id: <2F05A390F72A0A409390E016D23E45E8042DBEB4@ns-bco-mse4.im.battelle.org> MIME-version: 1.0 Content-type: text/plain; charset="iso-8859-1" X-SW-Source: 2002-10/txt/msg00239.txt.bz2 Certainly it is legal as far as the standard is concerned, "A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type." However, it may not be safe, "If the resulting pointer is not correctly aligned for the pointed-to type, the behavior is undefined." --Matt > -----Original Message----- > From: Claudio Bley [mailto:bley@cs.uni-magdeburg.de] > Sent: Monday, October 21, 2002 07:22 > To: Florian Weimer > Cc: Joshua Nye; Steve Dondley; gcc-help@gcc.gnu.org > Subject: Re: Avoiding "assignment from incompatible pointer type" > warning > > > >>>>> "Florian" == Florian Weimer writes: > > Florian> "Joshua Nye" writes: > >>> > int *p; > >>> > float g = 3.141592653589793238; > >>> > p = (int *)&g; > >>> > >>> Is this code legal? I doubt it. > >>> > >> 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? I mean, casting on the > machine code level does just nothing - it's just "syntactic sugar" to > convince the compiler to be quiet. I think casting from one pointer > type to another does no harm at all. Am I wrong? > > -- > Claudio Bley ASCII ribbon campaign (") > Debian GNU/Linux advocate - against HTML email X > http://www.cs.uni-magdeburg.de/~bley/ & vCards / \ >