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: sizeof with virtual inheritance


Hi Adrian,

>Your comments apply generally to multiple inheritance, you didn't say anything about virtual inheritance.

No, my comments were specifically about virtual inheritance.

Look at the memory layout of c4, which is 8 bytes:
c4 : byte[0 ... 3]
c4.c1 : byte[4]
c4.pad : byte[5 ... 7]

Those [0 ... 3] four bytes for the c4 portion (alone) of c4 contains the pointer for the multiple inheritance overhead.

- - - - - -

Look at the memory layout of c6, which is 2 bytes:
c6.c2.c1 : byte[0]
c6.c2.c3.c1 : byte[1]

Nothing interesting here. Straightforward.

- - - - - -

Look at the memory layout of c7, which is 12 bytes:
c7.c4 : byte[0 ... 3]
c7.c5. : byte [4 ... 7]
c7.c4.c1 & c7.c5.c1 : byte[8]
c7.pad : byte[9 ... 11]

The [0 ... 3] four bytes for the c7.c4 portion (alone) contains the c4 pointer for the multiple inheritance.

The [4 ... 7] four bytes for the c7.c5 portion contains the c5 pointer for the multiple inheritance.

The padding is alignment padding.

HTH,
--Eljay


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