C casts are dangerous!
You can't easily search for all C casts, unless you search specifically for the type like (int*) (char*) (float*)...
You can't tell why the cast was needed with a C cast. Did they need to remove const-ness, did they need to convert between related types, did they need to cast between base and derived classes...?
Like what King Mir pointed out, Stroustrup considers that a side benefit: "Maybe, because static_cast is so ugly and so relatively hard to type, you're more likely to think twice before using one? That would be good, because casts really are mostly avoidable in modern C++."Quote:
C++ casts are too long to type.
The hard copy version of the book does not provide any elaboration either, but I believe that Sutter and Alexandrescu are concerned because "the mapping performed by reinterpret_cast is implementation-defined", and thus "it might, or might not, produce a representation different from the original value" (section 5.2.10 of the C++ Standard (2003)), whereas for static_cast, 'a value of type pointer to object converted to "pointer to cv void" and back to the original pointer type will have its original value' (section 5.2.9 of the C++ Standard (2003)).Quote:
I don't think I fully understand it either; I just remember reading it in that book.
If anyone else here can explain what kind of danger the book is talking about, can you please enlighten us?
As for me, I don't work in projects with multiple people so I haven't had any problems searching for casts or wondering why they're there.
I'm experienced with types and I know exactly what they do - so using C casts have never really been a problem for me.
I typically do use const_cast to get rid of const whenever necessary, too.
The also long cast names serve as a yellow warning flag that something dangerous is going on.