title: No compliant way to convert signed/unsigned of same size
body: <p>I fear I may be missing something trivial, but it appears there is no actual safe way to convert to/from a signed type if you wish to retain the original unsigned value.</p>
  
  <p>On reinterpret_cast, 5.2.10 does not list an integer to integer conversion, thus it is not defined (and static_cast defines no additional conversion). On integral conversions 4.7.3 basically says conversion of a large unsigned will be implementation defined (thus not portable).</p>
  
  <p>This seems limiting since we know, for example, that a <code>uint64_t</code> should, on any hardware, be safely convertible to a <code>int64_t</code> and back without change in value. Plus the rules on standard layout types actually guarantee safe conversion if we were to <code>memcpy</code> between the two types instead of assign. </p>
  
  <p>Am I correct? Is there a legitimate reason why one cannot <code>reinterpret_cast</code> between integral types sufficient size?</p>
  
  <hr>
  
  <p><em>Clarification: Definitely the signed version of the unsigned is not guaranteed a value, but it is only the round-trip that I am considering (unsigned => signed => unsigned)</em></p>
  
  <hr>
  
  <p><strong>UPDATE</strong>: Looking closely at the answers and cross-checking the standard, I believe the <code>memcpy</code> is not actually guaranteed to work, as nowhere does it state that the two types are layout compatible, and neither are char types. Further update, digging into the C-standard this memcpy should work, as the sizeof the target is large enough and it copies the bytes.</p>
  
  <hr>
  
  <p><strong>ANSWER</strong>: There appears to be no technical reason why reinterpret_cast was not allowed to perform this conversion. For these fixed size integer types a <code>memcpy</code> is guaranteed to work, and indeed so long as the intermediate can represent all bit-patterns any intermediate type can be used (float's can be dangerous as there may be trap patterns). In general you can't memcpy between any standard layout types, they must be compatible or char type. Here the ints are special since they have additional guarantees.</p>