According to the Wikipedia page Segmentation fault, a bus error can be caused by unaligned memory access. The article gives an example about how to trigger a bus error. In the example, we have to enable alignment checking to see the bus error. What if we disable such alignment checking?
The program seems to work properly. I have a program access unaligned memory frequently, and it is used by quite a few people, but no one reports bus errors or other weird results to me. If we disable alignment checking, what is the side effect of unaligned memory?
Platforms: I am working on x86/x86-64. I also tried my program by compiling it with "gcc -arch ppc" on a Mac and it works properly.
alignof(T)
is undefined behaviour and can cause real-world problems even on x86, for example when auto-vectorizing the compiler may assume that a 16-byte alignment boundary is some whole number ofshort
s away : Why does unaligned access to mmap'ed memory sometimes segfault on AMD64? – Peter Cordes