4 ms·
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.
by stevenhuang 5mo 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 5mo agoThat 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-myth-or-reality/ 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)
- eru 5mo agoDon't mix up what processors do with what the C standard allows you to get away with.
- flohofwoe 5mo ago...and don't mix up the C standard with what actually existing compilers allow you to get away with ;) In the end the standard is merely a set of guidelines. What matters is how compiler toolchains behave in the real word, and breaking code which does unaligned memory accesses by 'UB exploitation' would be quite insane.
- eru 5mo agoSanity ain't a hard requirement for C compilers.
- dmitrygr 5mo agoWithout 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 BIC r3, r0, #3 Spec only guaranteed round-trip through char* of properly aligned for type pointers. This doesn’t break that.