Interview Question

What is strict aliasing?

Respect effective-type access rules; use memcpy for portable type representation copying.

💡 Concept ✅ Quick Revision ⚙ C

Answer

Strict aliasing refers to C rules limiting which lvalue types may access an object’s stored value. • Compatible types and character types have specified access permissions. • Violating effective-type aliasing rules can produce undefined behavior and invalid optimizer assumptions. • Use memcpy for portable representation copying between unrelated object types.

💡 C Example

float source = 1.0f; unsigned int bits = 0; _Static_assert(sizeof bits == sizeof source, "size mismatch"); memcpy(&bits, &source, sizeof bits);

⚡ Quick Revision

Respect effective-type access rules; use memcpy for portable type representation copying.