Boost logo

Boost :

From: Mat Marcus (mmarcus-boost_at_[hidden])
Date: 2003-09-02 14:00:13

--On Tuesday, September 02, 2003 2:00 PM -0400 Douglas Gregor
<gregod_at_[hidden]> wrote:

> On Tuesday 02 September 2003 01:36 pm, Mat Marcus wrote:
>> We're trying to use optional from 1.30.0 (sorry legal hasn't
>> approved our use of 1.30.2 yet). However on one compiler
>> (Metrowerks 8.3 PPC CFM) we're getting static asserts from the
>> alignment calculation metafunctions. Below is an abstracted example
>> of the problem. I'm curious about what's going on and what
>> workarounds might be possible.
>> Thanks,
>> Mat
> Looks like the code was unable to find an 8-byte aligned type. Could
> you check the results of:
> std::cout << boost::alignment_of<double> << '\n';
> std::cout << boost::alignment_of<long double> << '\n';
> 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!).
> Doug

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;

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

Boost list run by bdawes at, gregod at, cpdaniel at, john at