Boost logo

Boost :

Subject: Re: [boost] [optional] Strict Aliasing Warnings on Trunk
From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2009-12-18 14:07:39


On Fri, Dec 18, 2009 at 4:57 PM, Emil Dotchevski
<emildotchevski_at_[hidden]> wrote:
> On Fri, Dec 18, 2009 at 5:46 AM, Felipe Magno de Almeida
> <felipe.m.almeida_at_[hidden]> wrote:

[snip]

>> 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.

It is not portable if we dereference it, which optional does.

>> 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.

I don't understand why.
How is reinterpret_cast better than static_cast?

> Emil Dotchevski
> Reverge Studios, Inc.
> http://www.revergestudios.com/reblog/index.php?n=ReCode

-- 
Felipe Magno de Almeida

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