4 ms·
There is also a footnote: 99) If the member used to read the contents of a union object is not the same as the member last used to store a value in the object,
by flohofwoe 2y ago
There is also a footnote:
99) If the member used to read the contents of a union object is not the same as the member last used to store a value in the
object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new
type as described in 6.2.6 (a process sometimes called "type punning"). This might be a trap representation.
...it all makes sense until that last sentence, maybe that's for really weird bit casts like trying to reinterpret an integer as float. FWIW the only place I used union type punning was in an Z80 emulator for the 16-bit register pairs, but that's no longer necessary, since modern compilers will optimize two consequitive byte reads into a single word read:
https://www.godbolt.org/z/or7Woc4TP https://www.godbolt.org/z/or7Woc4TP