r/C_Programming • u/anduygulama • Jun 09 '26
packed attribute for structs
Why don't C compilers automatically optimize/pack structures instead of requiring explicit attributes?
2
Upvotes
r/C_Programming • u/anduygulama • Jun 09 '26
Why don't C compilers automatically optimize/pack structures instead of requiring explicit attributes?
View all comments
Show parent comment
16
u/innosu_ Jun 09 '26
Unaligned read on unsupported architecture can be performed via 2 aligned read and bit operations. I believe that is what compiler is doing under the hood anyway for packed struct on ARM. It's very slow though, so that's why I wrote that.