Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

strict aliasing rule

The C++ rule that a pointer to one type may be assumed not to point at an object of an unrelated type, which lets the optimizer keep values in registers.

The strict aliasing rule ([basic.lval]) makes accessing an object through a glvalue of an unrelated type undefined behaviour, so the optimizer may assume an int* and a float* never refer to the same storage.

Examples

  • Reading a float's bits through an int* is undefined; std::bit_cast<std::uint32_t>(f) or std::memcpy is the defined way.

Read the full section →