
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