Discussion:
An memory layout issue in g++
(too old to reply)
孙朝阳
12 years ago
Permalink
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.
孙朝阳
12 years ago
Permalink
Forget to say, I test it on Debian, X86_64, g++ 4.7.1
Post by 孙朝阳
struct Foo{ virtual void foo() {} };
struct Bar{ virtual void bar() {} };
struct B { void* data; };
struct X : public B, Foo, Bar { };
{
data of B;
vptr of Foo;
vptr of Bar;
}
{
vptr of Foo;
data of B;
vptr of Bar;
};
{
data of B;
vptr of Foo;
vptr of Bar;
};
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.
Loading...