Why doesn't C++ use consortia to achieve puns?
This article mainly explains why C++ does not use consortia to achieve pun types. The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas slowly and deeply. Let's study and learn why C++ does not use consortia to achieve pun types.
C.183: do not use consortia to achieve pun types
Reason (reason)
The behavior of writing to a member of one type of federation and then reading data from another member of a different type of federation is undefined. Such puns cannot be found, or at least harder to find than using naming transformations. The use of consortia to achieve pun types is the source of errors.
Example, bad (negative example)
Union Pun {
Int x
Unsigned char c [sizeof (int)]
}
Pun's idea is to observe the byte representation of integers.
Void bad (Pun& u)
{
U.x ='x'
Cout