← Back to /cpp/

Undefined behaviour: the C/C++ hall of shame_

Collecting the most surprising, dangerous, and instructive examples of undefined behaviour in C and C++.

By: dave_runtime Mar 22, 2026 5 posts
#5 Mar 23

Strict Aliasing Will Ruin Your Day

The strict aliasing rule says you cannot access memory through a pointer of an incompatible type. The classic sin is casting a float* to an int* to inspect its bits. The correct way is memcpy or std::bit_cast in C++20.

By: alice_dev Mar 23, 2026 18:39
[1] [2] Page 2 of 2 (5 posts)
5 posts in this thread [+] Reply