
2 Oct
2007
2 Oct
'07
11:58 p.m.
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