Comment

Comment by colejohnson66

In C++, type punning through pointers and unions is undefined behavior. Even `reinterpret_cast<T>` isn’t allowed because of aliasing (IIRC). The only “defined” way to do type punning is a memcpy. A compiler targeting something like x86 would optimize out the memcpy.

For more information, see the C++20 final draft[0§7.6.1.9]

[0]: https://isocpp.org/files/papers/N4860.pdf

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton