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

Why does this function, when compiled with optimizations under strict aliasing, allow the compiler to assume the store through `f` does not affect `*i` and potentially return the stale value?

int aliased(int* i, float* f) { int before = *i; *f = 3.0f; return before; // compiler may treat *i as unchanged }