Boost logo

Boost :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2003-09-02 14:32:19


On Tue, 2 Sep 2003, Mat Marcus wrote:
> --On Tuesday, September 02, 2003 2:00 PM -0400 Douglas Gregor
> <gregod_at_[hidden]> wrote:
> > I suspect they are both '4', but that leaves me even more confused
> > as to why the alignment of std::pair<double, double> would be 8
> > (and how to get a POD type with alignment 8 for ourselves!).
>
> Yes, they are both 4. I suspect that the problem may have to do with
> some unusual alignment rules on this platform. I believe that the rule
> is something like: a double at the beginning of a struct forces 8 byte
> alignment, but a double in the middle does not. That is, given
>
> struct A {
> double d;
> int i;
> };
>
> struct B {
> int i;
> double d;
> };
>
> then:
> sizeof(A) == 16;
> sizeof(B) == 12;
> alignment_of<A>::value == 8;
> alignment_of<B>::value == 4;
>
> Fun, eh? I can double check the compiler release notes for the exact
> rule if you like.
>
> - Mat

Are there any other crazy rules like this that you know of? We could just
add "struct A" from above to the list of types, or if there is a
CodeWarrior-specific extension (e.g., something like "#pragma pack" or
"atttribute(aligned...)") we could start using compiler-specific
extensions to do this, which wouldn't be a bad thing to do anyway.

        Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk