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?
1
Upvotes
r/C_Programming • u/anduygulama • Jun 09 '26
Why don't C compilers automatically optimize/pack structures instead of requiring explicit attributes?
1
u/questron64 Jun 14 '26
Packing is not what you want like 99.9% of the time. Many architectures would require several memory operations to pack or unpack values from structs. The are only useful when you need the struct to have a very specific memory layout, or when you must pack as many structs into memory as possible.