This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/38297] O2 causes invalid code



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]