Boost logo

Boost :

From: Jason Shirk (jasonsh_at_[hidden])
Date: 2003-02-03 14:32:21

"David B. Held" <dheld_at_[hidden]> wrote in message
> What can you say about empty member optimization in VC6.5 and later?
> Also, do you have any idea why an empty class that inherits from
> non-empty bases would be bigger than the sum of the size of the bases?

> Obviously, trivial test cases do not show this behaviour, but the
> policy_ptr in the sandbox does (though you'll probably have to wait
> till Monday afternoon for me to check in the latest version).

We haven't made any intentional changes to our object model in this
area, so VC6 SP5 and later should be the same as earlier.

In some little tests, I am seeing unusual behavior where it looks like
the ZBO is being done in certain cases, but not in others. Simply
reordering the bases causes the size of the class to change. For

class C1 {};
class C2 { int i; };
class C3 {};
class D1 : C1, C2, C3 { int j; }; // sizeof(D1) == 8
class D2 : C3, C1, C2 { int j; }; // sizeof(D2) == 12

I wasn't aware of this quirk before today, so I can't explain it. I
knew we did the ZBO for a single zero size base, but it looks like it
happens in circumstances I wasn't aware of.

As for sizeof(Derived) > sum(sizeof all bases), they usual explaination
is alignment. Consider:

class C1 { char c; };
class C2 { int i; };
class C3 { char c; };
class D : C1, C2, C3 {}; // sizeof(D) == 12

Because the C2 subobject needs to be 4 byte aligned, there are 3 bytes
of padding b/w C1::c and C2::I in D.

Assuming this isn't the issue you are noticing, you'll need to send me a
preprocessed file and I'll take a look.

Jason Shirk
VC++ Compiler Team

Boost list run by bdawes at, gregod at, cpdaniel at, john at