This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: g++ and aliasing bools
- From: Joe Buck <jbuck at synopsys dot COM>
- To: dan at dberlin dot org (Daniel Berlin)
- Cc: mark at codesourcery dot com (Mark Mitchell),jbuck at synopsys dot COM (Joe Buck),neil at daikokuya dot demon dot co dot uk (Neil Booth),pcarlini at unitus dot it (Paolo Carlini), gcc at gcc dot gnu dot org (gcc at gcc dot gnu dot org)
- Date: Mon, 28 Jan 2002 09:22:17 -0800 (PST)
- Subject: Re: g++ and aliasing bools
On Sat, 26 Jan 2002, Mark Mitchell wrote:
> > > The argument can be extended to handle non-virtual single or multiple
> > > inheritance: from the C point of view,
Daniel Berlin writes:
> > This isn't obvious yet.
> >
> > You have to at least discuss zero-sized base classes and whether or not
> > GNU C handles them in the same way -- including cases like this:
> >
> > struct A {};
> > struct B : public A {};
> > struct C : public A {};
> > struct D : public B, C {};
> >
> > Here, D has size two to avoid having two A's at the same address.
> > If C did not derive from A, D would have size one. In GNU C, does:
> >
> > struct A {};
> > struct B { struct A __base1; };
> > struct C { struct A __base1; };
> > struct D {
> > struct B __base1;
> > struct C __base2;
> > };
> >
> > have size two?
> >
> No, it has size 0.
> > Does the variant where C is empty have size 1?
> Nope.
But the C aliasing rules completely ignore the question of size, so you're
bringing up a red herring. The rules have *nothing* to do with whether we
think that two objects have the same address! It doesn't even come up.
For that reason, you don't have to waste any time thinking about class
layout.