Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

An memory layout issue in g++

10 views
Skip to first unread message

孙朝阳

unread,
Sep 16, 2012, 9:44:12 PM9/16/12
to
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.

孙朝阳

unread,
Sep 16, 2012, 9:45:47 PM9/16/12
to
Forget to say, I test it on Debian, X86_64, g++ 4.7.1
0 new messages