As it says, type punning is when you have two pointers of different type, both pointing at the same location. Example:
// BAD CODE
uint32_t data;
uint32_t* u32 = &data;
uint16_t* u16 = (uint16_t*)&data; // undefined behavior
This code invokes undefined behavior in C++ (and C) since you aren't allowed to access the same memory location through pointers of non-compatible types (with a few special exceptions). This is informally called a "strict aliasing violation" since it violates the strict aliasing rule.
Another way of doing type punning is through unions:
// BAD C++ CODE
typedef union
{
uint32_t u32;
uint16_t u16 [2];
} my_type;
my_type mt;
mt.u32 = 1;
std::cout << mt.u16[0]; // access union data through another member, undefined behavior
This is also undefined behavior in C++ (but allowed and perfectly fine in C).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…