This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: sizeof with virtual inheritance
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Adrian Sandor <aditsu at yahoo dot com>, gcc-help at gcc dot gnu dot org
- Date: Fri, 07 May 2004 15:30:15 -0500
- Subject: Re: sizeof with virtual inheritance
- References: <loom.20040427T063657-37@post.gmane.org><6.0.3.0.2.20040427070648.01f97650@iplan-mn.corp.adobe.com><loom.20040507T201246-280@post.gmane.org>
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