Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-12-18 13:57:26
On Fri, Dec 18, 2009 at 5:46 AM, Felipe Magno de Almeida
> On Fri, Dec 18, 2009 at 6:11 AM, Emil Dotchevski
> <emildotchevski_at_[hidden]> wrote:
>> On Thu, Dec 17, 2009 at 11:17 PM, Dean Michael Berris
>> <mikhailberis_at_[hidden]> wrote:
>>> Really? I thought this was implementation-defined?
>> Sure, but it is specified that if you reinterpret_cast from T1* to
>> T2*, then reinterpret_cast the resulting T2* back to T1*, you'll get
>> the original value (as long as T2 doesn't have stricter alignment
> But nothing else is guaranteed. The compiler might very well increment
> it by one byte when casting to T2 and then decrement it when casting
> it back. It is perfectly valid behavior for reinterpret_cast.
It is perfectly portable as well.
> IMO we should be using static_cast<T2*>(static_cast<void*>(x)) which
> is not implementation-defined.
Casting to a pointer of unrelated type doesn't suite static_cast,
reinterpret_cast is a better choice.
Reverge Studios, Inc.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk