From owner-freebsd-current Mon Nov 11 4:57:27 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 4F83937B401 for ; Mon, 11 Nov 2002 04:57:25 -0800 (PST) Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4D17B43E3B for ; Mon, 11 Nov 2002 04:57:23 -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 gABCvBl21151; Mon, 11 Nov 2002 13:57:11 +0100 (MET) Date: Mon, 11 Nov 2002 13:57:11 +0100 (CET) From: Harti Brandt To: TOMITA Yoshinori Cc: FreeBSD-current@FreeBSD.ORG Subject: Re: gcc 3.2.1 optimization bug ? In-Reply-To: Message-ID: <20021111135051.H11404-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, TOMITA Yoshinori wrote: This is probably not a bug, but a feature. You are not expected to access a variable through a pointer to a non-compatible type. int and short are not compatible. (see your ISO C standard on this topic). Try to use ntohl(), htonl() for your problem. harti TY>For the source code below, compiling gcc -O2/-O3 seem to produce TY>incorrect code. TY> TY>----------------------------------- TY>#include TY>int main(int argc, char* argv[]) TY>{ TY> unsigned int x = 0x12345678; TY> unsigned short tmp; TY> printf("%x\n", x); TY> tmp = ((unsigned short *)&x)[0]; TY> ((unsigned short *)&x)[0] = ((unsigned short *)&x)[1]; TY> ((unsigned short *)&x)[1] = tmp; TY> printf("%x\n", x); TY> return 0; TY>} TY>----------------------------------- TY> TY> TY>% gcc -O1 a.c TY>% ./a.out TY>12345678 TY>56781234 TY> TY>% gcc -O2 a.c TY>% ./a.out TY>12345678 TY>12341234 TY> TY>% gcc -v TY>Using built-in specs. TY>Configured with: FreeBSD/i386 system compiler TY>Thread model: posix TY>gcc version 3.2.1 [FreeBSD] 20021009 (prerelease) TY> TY> TY> TY> TY>Is this a gcc bug or the source code problem ? TY> TY>To Unsubscribe: send mail to majordomo@FreeBSD.org TY>with "unsubscribe freebsd-current" in the body of the message TY> -- 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