This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52981

--- 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]