Boost logo

Boost :

Subject: Re: [boost] aligned_storage in unions
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2010-09-23 11:37:28

Hash: SHA1

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

"A value of type pointer to object converted to “pointer to cv void” and back
to the original pointer type will have its original value."
Version: GnuPG v1.4.9 (GNU/Linux)


Boost list run by bdawes at, gregod at, cpdaniel at, john at