From owner-freebsd-current Mon Nov 11 8:23:58 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 797B237B401 for ; Mon, 11 Nov 2002 08:23:56 -0800 (PST) Received: from dignus.com (sdsl-64-32-254-102.dsl.iad.megapath.net [64.32.254.102]) by mx1.FreeBSD.org (Postfix) with ESMTP id 89E8143E6E for ; Mon, 11 Nov 2002 08:23:55 -0800 (PST) (envelope-from rivers@dignus.com) Received: from lakes.dignus.com (lakes.dignus.com [10.0.0.3]) by dignus.com (8.11.6/8.11.3) with ESMTP id gABGBqR16476; Mon, 11 Nov 2002 11:11:52 -0500 (EST) (envelope-from rivers@dignus.com) Received: (from rivers@localhost) by lakes.dignus.com (8.11.6/8.11.3) id gABGIS155735; Mon, 11 Nov 2002 11:18:28 -0500 (EST) (envelope-from rivers) Date: Mon, 11 Nov 2002 11:18:28 -0500 (EST) From: Thomas David Rivers Message-Id: <200211111618.gABGIS155735@lakes.dignus.com> To: brandt@fokus.gmd.de, gallatin@cs.duke.edu Subject: Re: gcc 3.2.1 optimization bug ? Cc: FreeBSD-current@FreeBSD.ORG In-Reply-To: <20021111163918.Y13339-100000@beagle.fokus.gmd.de> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Harti Brandt wrote: > > Well, I just had a long discussion with a collegue about the topic. The > main problem is in the ISO-C standard, section 6.7 point 4 which states: > > All declarations in the same scope that refer to the same object or > function shall specify compatible types. > > This makes any fiddeling with a pointer of a type, that is different from > the type of the variable illegal. It also makes fiddeling with unions and > structs illegal. As far as I understand types are compatible when they > have the same type and type qualifiers. Structs are partly compatible when > they start with fields of the same type. So the only way to legally swap > integer values of any size is via arithmetic. Of course unions and > pointers may work with the given compiler version and optimisation level. > But, nothing in the standard guarantees you anything. That's it exactly! > > It may be possible that 6.5 (7) the last sentence allows you to access your > 32-bit or 64-bit value character-wise (although I'm not sure). > > harti > The C99 standard does seem to add an "exception" for access via character pointers. The C89 standard did not have that clause. As far as the union question - the answer is that you cannot "read" from a union from a different member than it was "stored" to. For example: char ch; union { int x; char c; } my_union; my_union.x = 10; ch = my_union.c; Technically, this is illegal in ANSI C, and not guaranteed to "work". Although it will likely "work" in just about every reasonable environment. (For some definition of "work" :-) ) - Dave Rivers - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message