
On Fri, Dec 18, 2009 at 5:46 AM, Felipe Magno de Almeida <felipe.m.almeida@gmail.com> wrote:
On Fri, Dec 18, 2009 at 6:11 AM, Emil Dotchevski <emildotchevski@gmail.com> wrote:
On Thu, Dec 17, 2009 at 11:17 PM, Dean Michael Berris <mikhailberis@gmail.com> wrote:
[snip]
Really? I thought this was implementation-defined?
Sure, but it is specified that if you reinterpret_cast from T1* to T2*, then reinterpret_cast the resulting T2* back to T1*, you'll get the original value (as long as T2 doesn't have stricter alignment requirements.)
But nothing else is guaranteed. The compiler might very well increment it by one byte when casting to T2 and then decrement it when casting it back. It is perfectly valid behavior for reinterpret_cast.
It is perfectly portable as well.
IMO we should be using static_cast<T2*>(static_cast<void*>(x)) which is not implementation-defined.
Casting to a pointer of unrelated type doesn't suite static_cast, reinterpret_cast is a better choice. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode