Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Why doesn't C++ use consortia to achieve puns?

Shulou Source: shulou.com Published: 2022-06-01 19:20:12 10月03日 Update

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

Tags: Type union union association learning difference content byte object member integer behavior primitive dangerous unfortunate action reason reverse that is train of thought Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS Linux Apple Shulou Tech Info