int != safe && int != ℤ
summary
C++ int is shown to be unsafe: undefined behaviour on overflow and divide‑by‑zero, MISRA static checks miss cases, and plain promotions create surprising signed/unsigned flips. Implements three single-header libraries (modular wrap, overflow-detecting integers that raise or throw, and saturation arithmetic), uses GCC/Clang builtins or 64‑bit widen checks, reports multiplication overflow ≈99.99999% for random ints, demonstrates enum class has no codegen penalty while class return can force stack on MSVC, and adds SFINAE compile‑time checks.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:46Int not safe in programming
- 3:50C++ int definition limits
- 10:00Undefined behavior with integer operations
- 17:21Probability of undefined behavior
- 24:38Consequences in practice
- 29:18Safer integer arithmetic
- 33:35Three safer integer approaches
- 35:41Overflow detection integers
- 42:17Detecting overflow in addition and multiplication
- 46:14Safer integer types
- 50:38Compile-time constraints testing
- 52:45Saturation arithmetic
- 56:20Conclusion and key takeaways
related talks
01h 13mPractical Tips for Safer C++
01h 02mPractical Tips for Safer C++
58mCorrect Use of Integers in Safety-critical Systems
39mMitigating Integer Overflow in C
59mTo Int or To Uint
01h 05mSafer C++ with MISRA-C++ 2023
33mUndefined Behavior in C++: What Every Programmer Should Know and Fear
01h 30mDangerous Optimizations in C and C++ Programming Languages
