Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is there any sort of speed difference?
Is there any reason to prefer static_cast<> over C style casting? Are they equivalent?
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.
C++ style casts are checked by the compiler. C style casts aren’t and can fail at runtime.
Also, C++ style casts can be searched for easily, whereas it’s really hard to search for C style casts.
Another big benefit is that the 4 different C++ style casts express the intent of the programmer more clearly.
When writing C++ I’d pretty much always use the C++ ones over the the C style.