This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Member offsets in multiple inheritance


pieniek writes:

Hello,

I have always though, that given a pointer to an object, members are at (this) + (member-offset). But this cannot be true for multiple inheritance, no?

Example:

struct A {
   int x,y;
}

struct B {
   int a, b, c;
}

struct C : public A, public B {}

int func (B* b, B* actuallyCinstance) {	
    return b->b + actuallyCinstance->b;
}

How is the B::b member accessed, especially b->b when b is B? What is the cost of that (x86_64)?

Both pointers received by func() are pointers to an instance of the B class. The offset is the same.


If the caller invokes func() with the second argument being a pointer to an instance of C, the caller adjust the pointer to point to C's superclass, and invokes func() with two pointers to an instance of B.


Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]