
2 Oct
2007
2 Oct
'07
10:32 a.m.
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