Earlier quoted context omitted.
uint8_t foo[4]; *(uint32_t*)foo = 0; Besides even without strict aliasing, the above is not at all guaranteed to work since not all architectures support unaligned loads. So, the interesting thing about this example is that it does work. It's in fact very, very difficult to find a platform where that example won't work (i.e. crashes the program). For example, any C library involving image manipulation is likely going…
> It's in fact very, very difficult to find a platform where that example won't work No, it isn't. Many ARM processors will bus error on that code if (foo & 3) != 0. I believe PowerPC doesn't do unaligned word reads either... It quite often has to do with the memory controller and not with the particular processor, though I believe x86 has to support unaligned reads. I've certainly worked first hand with ARMs that di…
Would
uint8_t foo[4]; *(uint32_t*)(&foo[0]) = 0;
also result in a bus error? Why?