Zig Compiler's Behavior in Regards to "Strict Aliasing"

Ugh, so using a union in C to type pun is sort of allowed. It’s maybe the single most confusing piece in the C standard in my opinion lol. This comment on another thread on Ziggit is pretty good at explaining:

Basically in practice, it always works to type pun through a union. But it’s sort of murky whether or not it’s completely kosher via the standard. You are completely correct though that as of C++20 std::bit_cast is the “canonical” way to type pun in C++ and should be used over memcpy.

1 Like