This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51885] g++ compiler options -O2 and -O3 modifies program results
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 20 Jan 2012 19:31:48 +0000
- Subject: [Bug c++/51885] g++ compiler options -O2 and -O3 modifies program results
- Auto-submitted: auto-generated
- References: <bug-51885-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51885
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-20 19:31:48 UTC ---
(In reply to comment #4)
> i am quite sure there is something strange : reinterpret_cast is used to cast a
> float pointer to a uint32_t pointer
>
> these two types have the same size (4 bytes)
>
> therefore, the swap function (following the reinterpret_cast) should work
> properly ...
No, the C++ standard says your code has undefined behaviour.
Please read the section "Casting does not work as expected when optimization is
turned on" at http://gcc.gnu.org/bugs/#nonbugs_c and the article it links to,
http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html