|
Boost : |
Subject: Re: [boost] Silent change in boost 1.36 alignment_of<> template with gcc 4.3
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-11-10 05:42:51
On Sun, Nov 9, 2008 at 7:42 AM, Jon Biggar <jon_at_[hidden]> wrote:
> David Abrahams wrote:
>>
>> on Sat Nov 08 2008, Mathias Gaunard <mathias.gaunard-AT-ens-lyon.org>
>> wrote:
>>
>>> Jon Biggar wrote:
>>>
>>>> Unfortunately, this broke some code I had written that did structure
>>>> introspection,
>>>> because gcc's __alignof__() returns 8 for double on the x86
>>>> architecture, but
>>>> actually only aligns doubles on 4 byte boundaries inside structures.
>>>
>>> I personally never understood why gcc's alignof returns that.
>>> It doesn't even make sense, since the size of double is not a multiple of
>>> 8, so
>>> multiple doubles right after each other can't possibly be 8-byte aligned.
>>
>> We could easily either specialize our way around it or limit the result
>> of alignment_of<T> to sizeof(T). The latter seems like a smart thing to
>> do anyway.
>>
>> Thoughts?
>
> I'm becoming convinced that we just shouldn't us the __alignof__() builtin
> from gcc because it lies.
>
I wouldn't say it likes; from gcc __alignof__ docs:
" Some machines never actually require alignment; they allow reference
to any data type even at an odd address. For these machines,
`__alignof__' reports the _recommended_ alignment of a type."
x86 is one of those machines (no alignment ever required except for
some XMM instructions). The recommended alignment for double is 8
bytes, even if the ABI, for historical reason only requires 4.
-- gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk