clanmjc wrote: |
---|
[C-style casts] are like using reinterpret_cast for all your casts, which carries it's own risk. |
Ehhh.. C-style casts are not the same as reinterpret_cast....
static_cast, const_cast, dynamic_cast, and reinterpret_cast all do distinctly different things.
1) static_cast converts between types, doing "hidden" pointer math where appropriate
2) const_cast removes type qualifiers without doing any type conversion.
3) dynamic_cast does the job of static_cast, but does runtime checks to ensure the cast is good
4) reinterpret_cast forcibly converts between types, without doing any hidden conversion or pointer math. The data is taken "as-is" and simply reinterpretted (hence the name).
These are 4 distinct jobs that do different things. So in C++ you're given 4 different tools, one to address each situation.
C-style cast is sort of an all-in-one that meshes all of them together (except for dynamic_cast, which a C style cast cannot perform).
When doing a C-style cast.... whether you get a static, a const, or a reinterpret cast depends entirely on the context, so it's less verbose and more prone to "gotcha"s. What's worse, the vast majority of "gotchas" will surface as runtime bugs instead of compiler errors.