17 ms·
In addition to breaking strict aliasing and alignment as other have pointed out, your first example also assumes little endian and won't work on big endian arch
by brigade 15y ago
In addition to breaking strict aliasing and alignment as other have pointed out, your first example also assumes little endian and won't work on big endian architectures.
Just don't do it unless it's a quick hack that you absolutely know you'll rewrite correctly within the day, before committing. And even then, write it correctly the first time around.
- mansr 15y agoThis construct does not depend on byte order since both sides are using the same (unsafe) type-punning.