D pointers

George Staikos staikos at kde.org
Tue Oct 4 04:10:27 BST 2005

On Monday 03 October 2005 20:48, Thiago Macieira wrote:
> George Staikos wrote:
> >  struct oldPixmapType { QPixmap a, b; };
> >  mutable union {
> >    struct {
> >      QPixmap *icon, *miniIcon;
> >    } pm;
> >    char unused[sizeof(oldPixmapType)];
> >  } aIconPixmap; // KDE4: remove me
> >
> >  Here we were even able to reuse the space so we didn't need to add to
> > the d-pointer.
> That's really ingenious. I hadn't thought of that!
> However, even though that guarantees the proper sizeof, it doesn't
> guarantee __alignof and, hence, the necessary padding.
> You can solve that by adding one element to the union which has the same
> alignment requirements that QPixmap has. The hard part is figuring out
> which one that is.
> So in general I don't think it's not a good idea to replace complex types
> with POD. The conclusion I come to is: if you're going to place a
> variable outside the private class, at least use POD types.

  I seem to recall that we went through this and determined that alignment was 
going to be correct so we didn't need to do anything different.  Well maybe 
until we run on 128-bit systems?

  Actually don't the pointers guarantee we are aligned properly anyway?

George Staikos
KDE Developer				http://www.kde.org/
Staikos Computing Services Inc.		http://www.staikos.net/

More information about the kde-core-devel mailing list