public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52981] New: Separate -Wpacked into two options
@ 2012-04-13 18:31 akurland at digi dot com
  2012-10-24 15:22 ` [Bug c/52981] " akurland at digi dot com
  2015-04-24  1:55 ` [Bug c/52981] Separate -Wpadded " david at doublewise dot net
  0 siblings, 2 replies; 3+ messages in thread
From: akurland at digi dot com @ 2012-04-13 18:31 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52981
           Summary: Separate -Wpacked into two options
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: akurland@digi.com


The option -Wpacked reports two different warnings:

1. warning: padding struct to align ‘<member name>’
2. warning: padding struct size to alignment boundary

The first warning indicates that the structure can be reordered in such a way
as to reduce padding. The second warning simply indicates that the structure is
not a multiple of the largest primitive data type and required padding at the
end.

I find the first warning much more interesting than the second one.
Specifically I would like to control them individually using -Werror.

If we can add something like -Wpacked-align and -Wpacked-size as additional
options (while still preserving the behavior of -Wpacked) I think this would be
a valuable addition to GCC.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/52981] Separate -Wpacked into two options
  2012-04-13 18:31 [Bug c/52981] New: Separate -Wpacked into two options akurland at digi dot com
@ 2012-10-24 15:22 ` akurland at digi dot com
  2015-04-24  1:55 ` [Bug c/52981] Separate -Wpadded " david at doublewise dot net
  1 sibling, 0 replies; 3+ messages in thread
From: akurland at digi dot com @ 2012-10-24 15:22 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Aaron S. Kurland <akurland at digi dot com> 2012-10-24 15:22:28 UTC ---
I just realized that my original message was referring to the wrong option. I
meant: -Wpadded

I am therefore requesting two new options:

-Wpadded-element and -Wpadded-structure

Sorry for the confusion.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/52981] Separate -Wpadded into two options
  2012-04-13 18:31 [Bug c/52981] New: Separate -Wpacked into two options akurland at digi dot com
  2012-10-24 15:22 ` [Bug c/52981] " akurland at digi dot com
@ 2015-04-24  1:55 ` david at doublewise dot net
  1 sibling, 0 replies; 3+ messages in thread
From: david at doublewise dot net @ 2015-04-24  1:55 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-24  1:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-13 18:31 [Bug c/52981] New: Separate -Wpacked into two options akurland at digi dot com
2012-10-24 15:22 ` [Bug c/52981] " akurland at digi dot com
2015-04-24  1:55 ` [Bug c/52981] Separate -Wpadded " david at doublewise dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).