lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Apr 7, 2012 at 4:10 PM, liam mail <liam.list@googlemail.com> wrote:
> On 7 April 2012 20:20, Coda Highland <chighland@gmail.com> wrote:
>>> Whether you agree of not does not really matter,static_cast is the
>>> correct cast to use and the result of reinterpret_cast is mostly
>>> implementation specific.
>>
>> No, it's quite well-defined: "Converting a prvalue of type “pointer to
>> T1” to the type “pointer to T2” [...] and back to its original type
>> yields the original pointer value." The fact that the C++03 spec
>> doesn't make it clear that void* is allowed as T1 or T2 in this
>> context is in fact an error and the C++11 spec corrects this (see
>> defect 1120) -- and this is how every C++ compiler in common use does
>> it. So reinterpret_cast'ing to void* and back is guaranteed safe.
>>
>> /s/ Adam
>>
>
> Arrr erm :)
>
> Whilst this change is not in the last draft[1], as you said the
> explicit operation is allowed by ISO C++11[2]. However the fact that
> it is was not in any earlier standards would make it undefined in
> those, as only casts which are listed are defined.
>
> So yes it is valid in C++11 yet still invalid for the earlier
> standards, with static_cast being correct in all standards.
>
> [1] I am not even going to rant about how silly it is that only the drafts ....
> [2] 1120 as noted by Coda
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1120

Not undefined, implementation defined. ;) And gcc and MSVC both define
this operation to work. :P

/s/ Adam