|
Boost : |
Subject: Re: [boost] aligned_storage in unions
From: David Abrahams (dave_at_[hidden])
Date: 2010-09-23 13:18:22
On Sep 23, 2010, at 11:37 AM, Frank Mori Hess wrote:
> On Thursday 23 September 2010, David Abrahams wrote:
>> On Sep 22, 2010, at 4:01 PM, Mathias Gaunard wrote:
>>> On 22/09/2010 20:43, David Abrahams wrote:
>>>> static_cast through void*, please. That has defined behavior
>>>
>>> AFAIK, not if you don't cast back to exactly the same type that was
>>> converted to void*.
>>
>> Yes, in many cases, even if you don't. For example, if you want to access
>> the raw bytes of an object, you can do
>>
>> static_cast<char*>(static_cast<void*>(&x))
>>
>> Also, if you happen to know that X is a POD struct beginning with an int,
>> you can
>>
>> *static_cast<int*>(static_cast<void*>(&x)) = 0;
>
> What is this based on? There is a strict aliasing exception for char*, but
> all I see in the standard about static_casting through void is (paragraph 10
> of 5.2.9):
Sorry, no time to trawl the standard right now. The above matches my hard-won understanding but of course I could always be wrong about anything ;-)
-- Dave Abrahams BoostPro Computing http://boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk