[Bug c/52981] Separate -Wpadded into two options

david at doublewise dot net gcc-bugzilla@gcc.gnu.org
Fri Apr 24 01:55:00 GMT 2015


--- Comment #5 from David Stone <david at doublewise dot net> ---
After thinking about this some more, we are not answering the question that
splitting it into two warnings is really trying to get at.

The first, and most important is not "Is there padding in the middle of the
structure", but "Can I rearrange my data members to save space?".
-Wwasted-space might be a good name for this warning. I believe in all systems
that gcc targets*, the optimal size can be achieved by arranging elements
largest to smallest, so we could just compare the size of a theoretical struct
with that arrangment and the size of the user's struct.

The second thing the user might wonder is "Do I have padding that I cannot
resolve by rearranging". This warning can alert the user that a small change in
the size of their data types (or possibly moving data into different
structures) could have a greater-than-expected size savings. This is more like
the current -Wpadded.

* A strange system with 4-byte, 3-byte, and 1-byte aligned types could have a
more efficient representation by following every 3 with a 1. I am unsure if
this is actually valid according to the C or C++ standard. As long as all of
the systems just have power-of-two alignment, the largest to smallest works.

More information about the Gcc-bugs mailing list