HiveBrain v1.2.0
Get Started
← Back to all entries
gotchacppCritical

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

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
andstylebetweenthedifferencestatic_castwhatcasting

Problem

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

Solution

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.

Context

Stack Overflow Q#1609163, score: 324

Revisions (0)

No revisions yet.