Possible Duplicate:
Should I use static_cast or reinterpret_cast when casting a void* to whatever
Often, especially in Win32 programming it is required to cast from one opaque type to another. For example:
HFONT font = cast_here<HFONT>( ::GetStockObject( SYSTEM_FONT ) );
Both static_cast and reinterpret_cast are applicable here and have exactly the same effect since HFONT is a pointer to a dummy struct specifically introduced for defining HFONT and HGDIOBJ returned by GetStockObject() is a void* pointer.
Which one – static_cast or reinterpret_cast – is preferable?
Everybody has noted that reinterpret_cast<> is more dangerous than static_cast<>.
This is because reinterpret_cast<> ignores all type information and just assigns a new type without any real processing, as a result the processing done is implementation defined (though usually the bit patterns of the pointers are the same).
The thing everybody fails to mention is that reinterpret_cast<> is a means to document your program. It tells somebody reading the code that we had to compromise something and as a result we have ended up with a dangerous cast, and be careful when you mess with this code.
Use the reinterpret_cast<> to highlight these dangerous areas in the code.
When casting from a void* there is not type information for the cast to work with.
So you are either doing an invalid cast or a casting back to the original type that was previously cast into a void*. Any other type of casting is going to end up with some undefined behavior.
This is the perfect situation to use reinterpret_cast<> as the standard guarantees that casting a pointer to void* and back to its original type using reinterpret_cast<> will work. And by using reinterpret_cast<> you are pointing out to the humans that come along afterwords that something bad is happening here.