union で最後に書いたメンバと別のメンバを読み出すのも C++ では未定義動作だよ。 gcc は( -fstrict-aliasing の説明にもあるとおり)特別ルールを設けてある程度の保証を与えている状態。 https://gcc.gnu.org/bugs/#casting_and_optimization > To fix the code above, you can use a union instead of a cast (note that this is a GCC extension which might not work with other compilers):