5 ms·
C compilers should really refuse to compile code that does blatant type punning like this. Is there a book out there that is teaching people this is okay? Every
by CyberRabbi 5y ago
C compilers should really refuse to compile code that does blatant type punning like this. Is there a book out there that is teaching people this is okay? Everything I’ve ever learned about C/C++ has explicitly warned against type punning.
- wallaBBB 5y agoLow level embedded begs to differ
- wheybags 5y agoWell, reality is many real world projects depend on it. Eg linux, disables strict aliasing. IMO the strict aliasing rule is a mistake, people know how the code should behave, so it should behave as expected.
- josefx 5y ago> MO the strict aliasing rule is a mistake, people know how the code should behave, so it should behave as expected. The strict aliasing rule exists because without it a C compiler has to second guess every load and store, which would have been horribly slow in the 80s and would be even worse now. It still ends up doing that for distinct pointers with the same type, which is why you can explicitly restrict them in newer language versions so the compiler can assume that those pointers wont alias.
- wheybags 5y agoWell the linux ptoject does just fine without strict aliasing based optimisations. Pretty much everything on windows is built with msvc, which doesn't depend on strict aliasing for optimisation either.
- CyberRabbi 5y agoLinux also depends on GCC or compilers that share its behavior w.r.t. type aliasing.