|
Boost : |
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2007-10-02 06:32:22
David Abrahams wrote:
> on Fri Sep 21 2007, "Marco Servetto" <marco.servetto-AT-gmail.com> wrote:
>
>> struct A{
>> int a1;
>> double a2;
>> int a3[3];
>> };
>> struct B{
>> int b1;
>> double b2;
>> int b3[3];
>> };
>>
>> The question is: C++ grants that
>> A a;
>> a.a2=8.8;
>> assert(reinterpret_cast<B*>(&a)->b2==8.8);
>>
> C++ guarantees very, very little about reinterpret_cast, and certainly
> not that.
>
The rules about layout compatibility of POD structs seem to guarantee
exactly that. I don't know how else to interpret them - that is, how
else to even be in a situation where the compatibility rules apply,
except by using reinterpret_cast or a C-style cast.
Sebastian Redl
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk