lua-users home
lua-l archive

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


On Sat, Apr 7, 2012 at 11:07 AM, Patrick Rapin <toupie300@gmail.com> wrote:
>> This HAS to be a reinterpret_cast because all casts through void* are
>> considered unsafe by the compiler.
>
> Sorry, but this is wrong.
> A compiler will generate error when using static_cast to convert
> between *unrelated* pointer types.
> The generic void* pointer is considered related with all T* pointers
> (without const or volatile qualifier).
> Also, the cast from A* to B* is accepted by static_cast if B derives
> from A (the other way round, converting B* to A* does not need any
> cast of course).

I'd still make it a reinterpret_cast even if the compiler allows it
because I disagree with the notion that void* is related. It really is
a reinterpretation of the pointer -- from a known type to an opaque
one. It's not becoming more or less specific like a static_cast would
imply; it's completely losing all of its type information. So spec or
not, the idea of what the casts are supposed to be makes void*
conceptually a reinterpret_cast even if the compiler allows
static_cast.

/s/ Adam