Quote:
Originally Posted by dmail
This is not correct as the OP is using C and a cast from void pointer to another type pointer is implicit.
|
Actually it's the other way around. Any pointer will implicitly cast to
void* but you must explicitly cast
void* to turn it into something else. That's because
void* is useless and you shouldn't be able to implicitly make it into an arbitrary useful type. Polymorphism doesn't work with
void*, either, which is another reason. Take for example
Code:
class A {};
class B : virtual public A {};
A
B* cast to a
void* should only be cast back to
B* or to
unsigned char*, even if just to further cast to
A*. You'll end up with an invalid pointer if you cast the
void* directly to
A*, hence the requirement for explicit casting.
Technically you should be using
unsigned char* because that's the standard binary representation of data.
char* may be signed, and as such could have anomalous effects when performing binary operations.
ta0kira
Edit: I think you might be right in a normal C context as far as implicit casting. I guess I'm thinking in terms of C++.