孙朝阳
12 years ago
I searched the ABI description in http://mentorembedded.github.com/cxx-abi/cxx-vtable-ex.html & http://www.phpcompiler.org/articles/virtualinheritance.html, and didn't found the exactly description for the following case:
struct Foo{ virtual void foo() {} };
struct Bar{ virtual void bar() {} };
struct B { void* data; };
struct X : public B, Foo, Bar { };
I expected the memory order of bases is:
{
data of B;
vptr of Foo;
vptr of Bar;
}
but the actual result is:
{
vptr of Foo;
data of B;
vptr of Bar;
};
if both Foo and Bar has no virtual functions, the result would be:
{
data of B;
vptr of Foo;
vptr of Bar;
};
So, I can't judge the memory layout for the following code:
template<typename A, typename B, typename C>
struct Mix : public A, B, C {}
So, I want to know, is it a bug of gcc? Is the case clarified in any standards?
Great thanks for any information.
struct Foo{ virtual void foo() {} };
struct Bar{ virtual void bar() {} };
struct B { void* data; };
struct X : public B, Foo, Bar { };
I expected the memory order of bases is:
{
data of B;
vptr of Foo;
vptr of Bar;
}
but the actual result is:
{
vptr of Foo;
data of B;
vptr of Bar;
};
if both Foo and Bar has no virtual functions, the result would be:
{
data of B;
vptr of Foo;
vptr of Bar;
};
So, I can't judge the memory layout for the following code:
template<typename A, typename B, typename C>
struct Mix : public A, B, C {}
So, I want to know, is it a bug of gcc? Is the case clarified in any standards?
Great thanks for any information.