I was just reading this thread: Simple c++ pointer casting
And that got me to thinking why a static_cast between different pointer types is not allowed (except in the cases in which it is) unless you static_cast to a void* as an intermediary step. It seems to me that either both or neither should be allowed. Here is an example:
char* cs;
unsigned char* ucs;
cs = reinterpret_cast<char*>(ucs); // 1) allowed, of course
cs = static_cast<char*>(ucs); // 2) not allowed: incompatible pointer types
cs = static_cast<char*>( static_cast<void*>(ucs) ); // 3) now it's allowed!
It seems to me that if #3 is possible then #2 should be allowed as well. Or conversely, if #2 is not allowed on the grounds that the pointers are not compatible (necessitating a reinterpret_cast) then perhaps static_casting from a void* to anything should not be allowed on the grounds of pointer incompatibility. (Casting to a void* from any other pointer is always okay, of course.)
So why isn't one of those possilities true - that #2 and #3 are either both allowed or neither allowed? Why does it instead work as shown in my example?