As far as I know, all 'traditional' ways of doing this, namely reinterpret_cast
of a pointer and union
with int
and float
fields are UB as violation of strict aliasing (in C++, not in C).
So, how to do it correctly without undefined behavior?
Can I do a reinterpret_cast
to char *
and memcpy that to uint32_t? Or maybestd::launder
will help?