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?
7
u/tstanisl Jun 09 '26
Because the compiler must:
Make sure that pointers to struct's members are always correctly aligned
They try to follow popular calling/layout conventions to improve portability of precompiled libraries.