Misusing reinterpret_cast?! You Probably Are :) (Keynote)
summary
reinterpret_cast often hides undefined behavior: strict aliasing violations, lifetime-start bugs when casting bytes to objects, unaligned accesses that can fault or cost ~10%, and surprising ABI-dependent results (int↔float bit-punning and bool reads differ between compilers). Practical fixes: prefer std::bit_cast for same-size reinterprets, use std::launder or memcpy/memmove to start lifetimes, prefer dynamic_cast/static_cast when possible, and run UB sanitizer in CI. A ready-made option exists as the Safe Casting Library that wraps these patterns safely.
AI-written summary · about
chapters (15)
- 0:00Introduction and Context
- 3:51Storytelling and Survey
- 11:15Reinterpret Cast Basics
- 14:24Casting Rules and Aliasing
- 17:00Dynamic Cast vs Reinterpret Cast
- 22:33Strict Aliasing Pitfalls
- 27:52Floating Point and Integer Issues
- 30:35Bitcast and Type Sizes
- 31:40Boolean Representation Risks
- 33:39Memory Alignment Issues
- 37:19Safe Object Lifetime Management
- 41:05Lifetime Operations in C++20/23
- 46:03Summary and Best Practices
- 48:59Safe Casting Library Deep Dive
- 1:00:54Q&A Session
