Multiple ChoiceHard 45s
Strict aliasing and type punning legality
Which of the following is the standard-sanctioned way to reinterpret an object's bits as another type without violating strict aliasing?
Options
- 1reinterpret_cast of a pointer to the target type and dereference it (legal when sizes match)
- 2unions of unrelated types read through the inactive member (legal when sizes match)
- 3std::bit_cast to the target type (given equal size and trivially copyable types)
- 4memcpy into the target type is never legal for this purpose, even for trivially copyable types
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.