9 ms·
I wish the myriad articles about this interesting hack would bother to mention that it relies on undefined behaviour. Any time you find yourself doing this:
by rcfox 13y ago
I wish the myriad articles about this interesting hack would bother to mention that it relies on undefined behaviour. Any time you find yourself doing this:
*(foo*)
you're probably breaking the strict aliasing rule.
- deleted 13y ago[deleted]
- figglesonrails 13y agoFWIW, memcpy(&anInt, &aFloat, sizeof(int)) achieves the same thing, is not turned in a real call to memcpy(), and doesn't not break the strict aliasing rule, and does not cause incorrect code to be generated with using `gcc -fstrict-aliasing`.
- deletes 13y agoThe behavior is defined, if you disable the rule or your compiler doesn't follow it.