Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++strict aliasing rulesSingle-choice MCQ

Why does this 'type punning through a union' read behave differently in C versus C++, and what is the C++ verdict?

union U { float f; uint32_t u; }; uint32_t bits(float x) { U v; v.f = x; return v.u; // read the inactive member }