Re:Learning that you can use unions in C for grouping things...
by 10000truths on Sunday August 01, 2021 @05:39PM
(#28030284)
For 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.
Re:Learning that you can use unions in C for grouping things...
by formerly_proven on Monday August 02, 2021 @02:49AM
(#28033608)
Ah, right. Thanks for the correction.
The correct way to access packed structs is through memcpy, just like you'd access any other potentially unaligned object.