From: zhuyj > Sent: 19 October 2016 14:21 > __attribute__((packed)) is potentially unsafe on some systems. The > symptom probably won't show up on an x86, which just makes the problem > more insidious; testing on x86 systems won't reveal the problem. (On > the x86, misaligned accesses are handled in hardware; if you > dereference an int* pointer that points to an odd address, it will be > a little slower than if it were properly aligned, but you'll get the > correct result.) > > On some other systems, such as SPARC, attempting to access a > misaligned int object causes a bus error, crashing the program.
__attribute__((packed)) causes the compiler to generate byte memory access and shifts to access the unaligned data. You don't get a fault, just rather more instructions that you had in mind. You shouldn't really specify 'packed' unless there are real reasons why the data structure will appear on misaligned addresses. David