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

Given strict aliasing, which access through a differently-typed lvalue is well-defined and does NOT violate the aliasing rules?

long x = 0; char* cp = reinterpret_cast<char*>(&x); // (A) read *cp unsigned* up = reinterpret_cast<unsigned*>(&x); // (B) read *up struct W { long v; }; W* wp = reinterpret_cast<W*>(&x); // (C) read wp->v float* fp = reinterpret_cast<float*>(&x); // (D) read *fp