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*>
I want to covert a void* to char* reinterpret_cast and static_cast, which one is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s largely a question of style.
static_castcan do any conversionwhich is the opposite of an implicit conversion (and which doesn’t
remove
constorvolatile). Sincechar*tovoid*is implicit,static_castwould seem indicated; the usual rule is to usestatic_castin preference toreinterpret_castwhenever possible.Given that this use is particularly dangerous, some coding guidelines
might prefer
reinterpret_cast, to signal this fact.