On this page
C-Style Casts (Legacy)
Prev: C++ Named Casts | Up: builtins | Next: stdlib
Rel: C++ Named Casts
Ref: ISO C++ Core Guidelines — Avoid Casts
Tags: #public #prog #cpp #builtins #tier/legacy
Prefer Instead
Prefer C++ Named Casts (static_cast, std::bit_cast, dynamic_cast, const_cast) instead of C-style (T)expr casts.
Why It Is Legacy in C++
A C-style cast (TargetType)expr silently tries const_cast, static_cast, static_cast + const_cast, and reinterpret_cast in sequence until one compiles. It can accidentally strip const or reinterpret unrelated pointers during refactoring—and is nearly impossible to grep for in a large codebase.
Linked from
Related notes
- tuts/cpp/builtins/casts Linked here; links to this page; shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins Linked here; links to this page; shared tags: #builtins, #cpp, #prog
- tuts/cpp/stdlib Linked here; shared tags: #cpp, #prog
- tuts/cpp/builtins/auto shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins/classes_and_virtual shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins/concepts shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins/constexpr shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins/lambdas shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins/move_semantics shared tags: #builtins, #cpp, #prog, #tier
- tuts/cpp/builtins/namespaces shared tags: #builtins, #cpp, #prog, #tier