Re: sizeof with virtual inheritance

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux