Type punning done right
summary
Claims that safe type punning uses a memcpy pattern not pointer casts and that compilers typically optimize the memcpy away. Demonstrates the concrete trick of getting the next float by an integer increment on float bits, explains why undefined behavior via reinterpret_cast is the risk, and shows the minimal code pattern that copies bits into an integer, increments, copies back, and empirically compiles into efficient code.
AI-written summary · about
related talks
01h 01mEmbracing PODs Safely Until They Die
06mLightning Talk: Un-Undefining Undefined Behavior in C++
01h 02mEmbedded Friendly C++: Features That Make a Difference
07mThe Perils of Strict Aliasing
58mLeveraging C++20/23 Features for Low Level Interactions
42mWhat If We Pretended Unsafe Code Was Nice, And Then It Was?
45mBack to Basics: Casting
23mFunctional Programming in C++ (Run time vs Compile time types)
