Chapter 5.1
P.4: Ideally, a program should be statically type safe
Type safety is a security feature of C++
I rank type safety close to deterministic destruction among my favorite features of C++. Type safety tells different parts of your program what a bit pattern means. For example, here is the bit pattern for 1,729 as a 32-bit integer:
std::int32_t Ramanujan_i = 0b0000'0000'0000'0000'0000'0110'1100'0001;
Here is the bit pattern for 1,729 as a 32-bit unsigned integer:
std::uint32_t Ramanujan_u = 0b0000'0000'0000'0000'0000'0110'1100'0001;
As you can see, it is identical. However, consider the bit pattern for 1,729 as a float
:
float Ramanujan_f = 0b0100'0100'1101'1000'0010'0000'0000'0000; ...
Get Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.