This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/38297] O2 causes invalid code
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Nov 2008 11:43:06 -0000
- Subject: [Bug c++/38297] O2 causes invalid code
- References: <bug-38297-17012@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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