Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-10-02 19:58:40


on Tue Oct 02 2007, Sebastian Redl <sebastian.redl-AT-getdesigned.at> wrote:

> The implicit guarantee is there because there is no other way to convert
> the pointer except through a reinterpret_cast. (A C-style cast is
> defined in terms of the cast operator is takes the place of.)
>
> Layout compatibility is not mentioned anywhere else. So what does that mean?
>
> It means that, by the words of the standard, your code was not valid. On
> the other hand, making both structs the members of a union, then
> assigning one and reading the other, is valid. Make of that what you will.

If you want to make it valid, replace reinterpret_cast<X*>(a) with
static_cast<X*>(static_cast<void*>(a))

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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