|
|
Darren New <dne### [at] sanrrcom> wrote:
> Consider the case of "class alpha
> {int abc;}" for a counter-example - I know exactly how that's laid out due
> to the standard.
I don't think the standard specifies what kind of padding the compiler
will use between member elements.
For example, if you have a "struct { char c; int i; };", how many bytes,
if at all, are there between 'c' and 'i'?
Suppose you have "struct { int i; long l; };" in a 64-bit system. Will
the compiler put padding bytes between 'i' and 'l' or not?
Suppose you have:
class A {};
class B: public A { int i; };
sizeof(A) will be, per the C++ standard, at least 1. But what will be
sizeof(B), and consequently the offset of 'i' inside it? The standard
doesn't specify, and the compiler is free to optimize the empty base
class away or not, as it sees fit.
Oh, and it becomes even more complicated:
class A { int i1; public: virtual ~A(); };
class B1: virtual public A { int i2; };
class B2: virtual public A { int i3; };
class C: public B1, public B2 { int i4; };
Want to start guessing the offsets of the ints inside C? Good luck.
--
- Warp
Post a reply to this message
|
|