reinterpret_cast tells the compiler to ignore the pointed-to data type and pretend it has another type. Use it very sparingly: it communicates intent, but accepts responsibility for the result. section 5.6
A practical cast-maintenance rule:
- Prefer better-designed code that eliminates casts when possible. section 5.6
- Use reinterpret_cast when deliberately viewing binary numeric data through another representation. section 5.6
- Choose const_cast for constness, static_cast for compatible conversions, and dynamic_cast for checked polymorphic downcasts. section 5.6
Viewing an integer as bytes
A pointer to an integer can be reinterpreted as a char pointer, allowing its individual bytes to be read. The explicit cast exposes that representation-level intent instead of hiding it inside a C-style cast.
