October 15, 2002 | ||
Crazy ABI Layout Rules | ||
A couple of years ago, EDG was invited to participate in the development of an ABI (Application Binary Interface) for C++ on the Itanium architecture. The weekly development meetings ocurred in the Bay Area (SGI facilities), and since I lived close to there at the time, I represented EDG.
|
||
I hear you say “But what about templates?” Good reflex, but forget about those for now. Instead, let me rant about a more basic topic: Laying out subobjects in memory.
An object of type D contains three direct subobjects: a field i and two base subobjects (of types B1 and B2 respectively). Most of the time, each of these subobjects take up some bytes of memory within the sizeof(D) bytes occupied by D. One exception is that if a base class type is “empty” it may be optimized not to take up any space at all. Still, an optimized empty base class (OEBC) must have its own address.
then the base subobject of type B2 ends up inside the field of type int.
|
||
Posted by Daveed at 06:46 PM
| Comments (1)
|
||
I think parking the addresses of fake subobjects in the middle of real subobjects is brilliant. It means the claim in your book that the empty-base optimization doesn't extend nicely to empty members is not strictly correct.
I'm surprised, though, to find that Intel accepted such a tricky approach in their standard. It's the sort of thing I expect implementers to get wrong.