Interleaving members
Michael Ball
michael.ball at eng.sun.com
Fri Jun 18 17:32:15 UTC 1999
>I asked on the reflector: yes, given the class
> struct X {
> public:
> int a, b;
> public:
> int c, d;
> };
>it is legal to have the layout A C B D. This was intentional; we
>aren't just exploiting a loophole in the wording. Interestingly,
>Bjarne says that this was also true (and equally intentional) in
>the ARM.
>
>I still don't know of any implementation that actually does this.
In our case it's because we (Sun) consider it highly desirable to use the
C ABI whenever we can, and the obvious mapping onto a C struct is
considered valuable.
There is no strict technical reason for that. Rather, it's a stronly
held quasi-religious view. We would have to promise significant gains
to go against it.
In fact, there seems to be little to be gained, for two reasons.
1. There are very few structs or classes with both public and private
data elements. New classes aren't designed that way because it's widely
considered bad style. Most that do exist are there because they have
migrated from C code, and many still refer to the public parts from
C routines.
2. With the single exception of classes with lots of bitfields, there just
isn't that much padding to squeeze out. People who care seem to
follow the usual C rules about ordering by descending size.
This conclusion is the result of looking at lots of code. Still, there may
be a counter example out there.
-Mike-
More information about the cxx-abi-dev
mailing list