From owner-freebsd-current Mon Nov 11 8:33:34 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 EC88437B401 for ; Mon, 11 Nov 2002 08:33:32 -0800 (PST) Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id 98E6243E42 for ; Mon, 11 Nov 2002 08:33:30 -0800 (PST) (envelope-from brandt@fokus.gmd.de) Received: from beagle (beagle [193.175.132.100]) by mailhub.fokus.gmd.de (8.11.6/8.11.6) with ESMTP id gABGXGl08204; Mon, 11 Nov 2002 17:33:17 +0100 (MET) Date: Mon, 11 Nov 2002 17:33:16 +0100 (CET) From: Harti Brandt To: Thomas David Rivers Cc: brandt@fokus.gmd.de, , Subject: Re: gcc 3.2.1 optimization bug ? In-Reply-To: <200211111618.gABGIS155735@lakes.dignus.com> Message-ID: <20021111172959.W32091-100000@beagle.fokus.gmd.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 On Mon, 11 Nov 2002, Thomas David Rivers wrote: TDR>Harti Brandt wrote: TDR>> TDR>> It may be possible that 6.5 (7) the last sentence allows you to access your TDR>> 32-bit or 64-bit value character-wise (although I'm not sure). TDR> TDR>The C99 standard does seem to add an "exception" for access via TDR>character pointers. The C89 standard did not have that clause. Yes, thats the 6.5 (7) clause, but I'm not sure, because it does not speak about pointers. I don't fully understand what they mean :-( TDR>As far as the union question - the answer is that you cannot TDR>"read" from a union from a different member than it was "stored" TDR>to. TDR> TDR>For example: TDR> TDR> char ch; TDR> union { TDR> int x; TDR> char c; TDR> } my_union; TDR> TDR> my_union.x = 10; TDR> ch = my_union.c; TDR> TDR>Technically, this is illegal in ANSI C, and not guaranteed to "work". Although TDR>it will likely "work" in just about every reasonable environment. TDR>(For some definition of "work" :-) ) Hmm, I though the following would work: void foo(unsigned short *s) { unsigned short temp; temp = s[0]; s[0] = s[1]; s[1] = temp; } main() { int i = 0x12345678; foo(&i); printf("%08x\n", i); } because how would the compiler in main() know, that you do something wrong in foo(). But... if you compile this with -O5, it does not work! This is because the compiler inlines foo() into main and the program prints junk like 0x12342804. harti -- harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private brandt@fokus.gmd.de, brandt@fokus.fhg.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message