
On 14.12.2010 01:29, Dave Abrahams wrote:
At Mon, 13 Dec 2010 18:52:34 -0500, John Dlugosz wrote:
[1
] [1.1 ] A couple of times I've run into the situation where a "new" C++ class is written to exactly match "legacy" C structures. At the edges where old code meets new code, you can cast one to the other in-place. For example, given a huge mess of data that includes oldstruct s1; you could write the line newclass& s2= reinterpret_cast (s1); because s2 is designed to exactly overlay s1. Unless oldstruct and newclass are both POD, the above has implementation-defined behavior. The portable way to do it, if they indeed have the same layout, is newclass& s2= *static_cast
(static_cast (&s1)); 5.2.10p7 in the current draft defines the semantics of reinterpret_cast between standard-layout types via this double static_cast, so there is no difference.
Sebastian