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
4
u/innosu_ Jun 09 '26
Not totally accurate. Modern x86/amd64 only has unaligned penalty when crossing cache line size boundary, typically 64 byte. All unaligned access that does not cross the 64 byte alignment boundary does not have performance penalty at all.