What is the difference between static_cast<> and C style casting?

dicroce picture dicroce · Oct 22, 2009 · Viewed 96.8k times · Source

Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is their any sort of speed difference?

Answer

Glen picture Glen · Oct 22, 2009

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.