3 ms·
I agree, the article tells how but not why. I think there are two main reasons to prefer the C++ style casts. 1. The C style cast does too much. Some of the c
by RcouF1uZ4gsC 7y ago
I agree, the article tells how but not why.
I think there are two main reasons to prefer the C++ style casts.
1. The C style cast does too much. Some of the conversion it does are pretty safe, some are dangerous. The C++ casts try to differentiate the relatively safe casts from the dangerous casts. Any code with reinterpret_cast is worth taking extra time to scrutinize.
2. The second is that C style casts are hard to search for (Type). By giving names to these operations, you can more quickly search code for problematic areas.
3. Incorrect aliasing is a big deal. In the C and C++ standards it is undefined behavior, which means you lose the ability to reason about your program. Making the operations that can trigger this stand out is a good thing.