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.
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.