public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31176]  New: reorder class data members to minimize space waste
@ 2007-03-14 17:37 sebor at roguewave dot com
  2007-03-14 18:15 ` [Bug c++/31176] " fang at csl dot cornell dot edu
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: sebor at roguewave dot com @ 2007-03-14 17:37 UTC (permalink / raw)
  To: gcc-bugs

While discussing how today's C++ compilers lay out data members of structs and
classes on the C++ committee's mailing list the observation was made that no
known implementation, including gcc, takes advantage of the permission to
rearrange members declared with their own access specifier (see
c++std-core-11977). For example, the data members of the following struct are
laid out in declaration order even though a more space efficient order is
possible:

    struct S { public: char c; public: int i; public: char d; };

This problem is especially hard to solve in template code where the sizes of
one or more data members are not known, such as:

    template <class T, class U, class V>
    struct Triple { public: T a; public: U b; public: V c; };

Since reordering of existing structs would introduce a binary incompatibility I
would like to propose that a mechanism be provided whereby authors of new code
can mark up their types and/or data members in order to permit the compiler to
rearrange them in a space efficient manner, until gcc implements a new ABI
where the reordering algorithm becomes the default.

For example, a new type and/or variable attribute could be added (call it
reorder), that could be used to mark up types and/or data members to
participate in the reordering. To allow the compiler to arrange Triple members
in an efficient way the template would be marked up as follows:

    template <class T, class U, class V>
    struct Triple __attribute__ ((reorder)) {
       public: T a; public: U b; public: V c;
    };

or, alternatively, like so:

    template <class T, class U, class V>
    struct Triple {
       public: T a __attribute__ ((reorder));
       public: U b __attribute__ ((reorder));
       public: V c __attribute__ ((reorder));
    };

The order of members declared in the same section (introduced and closed by an
access specifier) without the attribute would not participate in the reordering
with one another.

Members of reordered aggregates would be initialized in declaration order.


-- 
           Summary: reorder class data members to minimize space waste
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com


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


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

end of thread, other threads:[~2014-09-03  0:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-31176-4@http.gcc.gnu.org/bugzilla/>
2014-09-03  0:56 ` [Bug c++/31176] reorder class data members to minimize space waste richard-gccbugzilla at metafoo dot co.uk
2007-03-14 17:37 [Bug c++/31176] New: " sebor at roguewave dot com
2007-03-14 18:15 ` [Bug c++/31176] " fang at csl dot cornell dot edu
2007-03-14 18:16 ` pinskia at gcc dot gnu dot org
2007-03-14 19:04 ` sebor at roguewave dot com
2007-03-14 19:06 ` sebor at roguewave dot com
2007-03-14 19:09 ` pinskia at gcc dot gnu dot org
2007-03-15 19:54 ` sebor at roguewave dot com
2007-03-15 19:55 ` sebor at roguewave dot com
2007-03-15 23:51 ` sebor at roguewave dot com
2007-04-28  0:37 ` pinskia at gcc dot gnu dot org

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