| ▲ | stevenhuang 4 hours ago | ||||||||||||||||
Byte and int has different alignment requirements. It is UB the moment you make such a ptr. Great way to demonstrate the point of the article. | |||||||||||||||||
| ▲ | gritzko 3 hours ago | parent | next [-] | ||||||||||||||||
That better be marked "historical". At least, Lemire says: On recent Intel and 64-bit ARM processors, data alignment does not make processing a lot faster. It is a micro-optimization. Data alignment for speed is a myth. // https://lemire.me/blog/2012/05/31/data-alignment-for-speed-m... (while in the olden days, a program may crash on unaligned access, esp on RISC) | |||||||||||||||||
| |||||||||||||||||
| ▲ | dmitrygr 3 hours ago | parent | prev [-] | ||||||||||||||||
Without memcpy there is no guarantee that that line produces an invalid pointer I don’t see what spec part would prohibit that cast from validly compiling to
Spec only guaranteed round-trip through char* of properly aligned for type pointers. This doesn’t break that. | |||||||||||||||||