3 ms·
C++ Casts
- makecheck 6y agoSome more notes on casting for completeness: - avoiding ambiguity is one reason to use C++-style casts but it’s especially a problem that you can’t search for C-style casts in a code base; C++-style casts are easier to find so you can scan code bases for possibly-incorrect behavior - it’s not entirely true that reinterpret_cast<> will not check anything; it can fail at compile time for invalid reinterpretations (e.g. you can’t convert between numeric types this way) - const_cast removes "const" but it can also remove "volatile" - it’s interesting that the const_cast<> example on an actual "const" variable does not work but this might just be undefined behavior (e.g. compiler choosing to locate value in read-only space or not)