3 ms·
Accessing packed struct members works fine on x86, but will blow up at runtime or do weird things on platforms which don't support unaligned loads or stores. T
by formerly_proven 5y ago
Accessing packed struct members works fine on x86, but will blow up at runtime or do weird things on platforms which don't support unaligned loads or stores.
The correct way to access packed structs is through memcpy, just like you'd access any other potentially unaligned object.
- 10000truths 5y agoFor architectures where unaligned accesses are illegal, gcc will generate multiple load/store instructions when accessing packed struct fields by name. The main caveat to look out for is taking the address of a packed struct member and then dereferencing it.
- formerly_proven 5y agoAh, right. Thanks for the correction.