I want to covert a void* to char* reinterpret_cast and static_cast, which one is fit for ?static_cast<char*> or reinterpret_cast<char*>
It's largely a question of style. static_cast
can do any conversion
which is the opposite of an implicit conversion (and which doesn't
remove const
or volatile
). Since char*
to void*
is implicit,
static_cast
would seem indicated; the usual rule is to use
static_cast
in preference to reinterpret_cast
whenever possible.
Given that this use is particularly dangerous, some coding guidelines
might prefer reinterpret_cast
, to signal this fact.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With