▲ | jcranmer a day ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Footnote 107 in C23, on page 75 in §6.5.2.3: > 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 non-value representation. (though this footnote has been present as far back as C99, albeit with different numbers as the standard has added more text in the intervening 24 years). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | ryao a day ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The GCC developers disagree with your interpretation: > Type punning via unions is undefined behavior in both c and c++. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|