From owner-freebsd-java Sat Feb 15 12:21:57 2003 Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D970737B401 for ; Sat, 15 Feb 2003 12:21:55 -0800 (PST) Received: from falcon.midgard.homeip.net (h76n3fls20o913.telia.com [213.67.148.76]) by mx1.FreeBSD.org (Postfix) with SMTP id E7C7A43F3F for ; Sat, 15 Feb 2003 12:21:52 -0800 (PST) (envelope-from ertr1013@student.uu.se) Received: (qmail 23596 invoked by uid 1001); 15 Feb 2003 20:21:51 -0000 Date: Sat, 15 Feb 2003 21:21:51 +0100 From: Erik Trulsson To: Huang wen hui Cc: java@FreeBSD.ORG, stable@freebsd.org Subject: Re: Optimization problem (Re: Math.pow bug for jdk1.3.1-p8 ?) Message-ID: <20030215202151.GA23574@falcon.midgard.homeip.net> Mail-Followup-To: Huang wen hui , java@FreeBSD.ORG, stable@freebsd.org References: <3E4C9DDD.4040204@gddsn.org.cn> <20030215.175421.1015281127.shudo@localhost> <20030216014802.A10817@misty.eyesbeyond.com> <20030216.005020.894433699.shudo@localhost> <3E4E7728.8030803@gddsn.org.cn> <3E4E86B8.2040608@gddsn.org.cn> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3E4E86B8.2040608@gddsn.org.cn> User-Agent: Mutt/1.5.3i Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Sun, Feb 16, 2003 at 02:28:08AM +0800, Huang wen hui wrote: > This is a simple one: > > #include > > #define __LO(x) *(int*)&x > > double tst() > { > double t1; > > t1=2; > __LO(t1) = 0; > return t1; > } > main() { > double d = tst(); > printf("%f\n", d); > > } The program above seems to be buggy. The line __LO(t1) = 0; after macro expansion looks like *(int*)&t1 = 0; where t1 is declared as a double, i.e. the program is accessing an object of type double through a pointer to type int. As far as I can tell this is not allowed by the C standard and therefore this program has undefined behaviour. This means that a compiler is allowed to do whatever it wants. That the program above exhibits different behaviour when compiled with -O0 (prints 2.000000) and when compiled with -O1 (prints 0.000000) does not seem to be a bug in the compiler but rather a bug in the program that happens to be triggered by the optimization process. -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message