5 ms·
Punning through the union is explicitly allowed in the GCC documentation which explains why it's reliable for use in the Linux kernel. See https://gcc.gnu.org/
by ChrisFoster 6y ago
Punning through the union is explicitly allowed in the GCC documentation which explains why it's reliable for use in the Linux kernel. See
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Type%2Dpunning https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Typ...
> you also have to assume the size of those primitive types
This usually works though there's some situations where you could still be surprised. For instance if you're programming embedded processors with avr-gcc you'll have sizeof(double)==4