From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14479 invoked by alias); 30 Nov 2008 11:44:26 -0000 Received: (qmail 14353 invoked by uid 48); 30 Nov 2008 11:43:06 -0000 Date: Sun, 30 Nov 2008 11:44:00 -0000 Message-ID: <20081130114306.14352.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/38297] O2 causes invalid code In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-11/txt/msg02626.txt.bz2 ------- Comment #13 from rguenth at gcc dot gnu dot org 2008-11-30 11:43 ------- Note that the C standard forbids type-punning through a union. Basically it says that you may only read from a union member if you have previously written to it. It also says that all other bits apart from the ones you have written to contain undefined values after the write. So union { int i; float f; } u; u.i = 1; x = u.f; invokes undefined behavior in C (but not in GNU C because of the language extension). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38297