Boost logo

Boost Users :

Subject: Re: [Boost-users] metaprogramming help
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2010-12-14 03:07:30


2010/12/14 Dave Abrahams <dave_at_[hidden]>

> 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<newclass*>(static_cast<void*>(&s1));

Using s2 causes undefined behavior (accessing an object through a pointer to
unrelated type). reinterpret_cast has the same problem and compilers taking
advantage of anti-aliasing rules can produce "unexpected" results for this
code.

Roman Perepelitsa.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net