Boost logo

Boost :

Subject: Re: [boost] aligned_storage in unions
From: David Abrahams (dave_at_[hidden])
Date: 2010-09-23 10:51:17


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;

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