<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br>On Jan 8, 2013, at 4:51 PM, <a href="mailto:dag@cray.com">dag@cray.com</a> wrote:<br><br><blockquote type="cite">David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> writes:<br><br><blockquote type="cite">General feedback: please send all patches for review as attachments,<br>not inline, so that mail clients don't mangle your patches.<br></blockquote><br>Ok, will fix the git config.<br><br><blockquote type="cite">It's still UB to access the non-active member of a union. I believe<br>the only valid way to do this sort of thing is with memcpy (you're<br>allowed to read/write the bytes of such simple types through char*s) &<br>let the compiler optimize that into the same trivial copy.<br></blockquote><br>Hmm.  Are you use this is UB?  It's the technique "everyone" seems to<br>recommend.  Unfortunately, I recently recycled my copy of the standard<br>in favor of the AVX2 spec.  :)<br></blockquote><br>For C, footnote 95 says the following:<div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>If the member used to read the contents of a union object</div></div><div><div>is not the same as the member last used to store a value</div></div><div><div>in the object, the appropriate part of the object representation</div></div><div><div>of the value is reinterpreted as an object representation in the</div></div><div><div>new type as described in 6.2.6 (a process sometimes called</div></div><div><div>‘‘type punning’’). This might be a trap representation. </div></div></blockquote><div><br>I am not aware of any similar language for C++, though I don't know the C++ standard nearly as well.  Either way, memcpy( ) is unambiguously correct and should generate good code.</div><div><br></div><div>- Steve</div></body></html>