6 ms·
This article spends a ton of time explaining very rudimentary things and then completely glosses over what it intends to convey. C-style casts aren't evil, but
by aaaronic 6y ago
This article spends a ton of time explaining very rudimentary things and then completely glosses over what it intends to convey.
C-style casts aren't evil, but they are powerful. They can also be used in places where more than one C++ cast would be required. C developers are very likely to use the C style because it mostly gets the job done the first try.
C developers working on C++ code are not likely to be swayed much by anything that doesn't make a strong case for having 4 different cast operators and this article doesn't manage to do that.
- RcouF1uZ4gsC 6y agoI 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.