Module 16 · Undefined Behaviour, Debugging and Reading Real C
Undefined Behaviour: the Rules You Did Not Know You Were Breaking
ProReading
Kenji's game adds bonuses to scores, and he worries about overflow. So he wrote a check: if x + 1 is smaller than x, the addition must have wrapped. He tried it on the Playground with the largest int, 2147483647.
Pro lesson
This one goes deeper
It is included with this track and with Learn Pro. Every question on the Skill Test can be answered from the free lessons, so this is depth and never a gate on the certificate.
What is inside Undefined Behaviour: the Rules You Did Not Know You Were Breaking
- Kenji's check, and what GCC 12 made of it
- Undefined behaviour is a contract with the compiler
- Undefined, implementation-defined, unspecified
- The gallery: nine promises you have met
- Two more deleted checks, in the listing
- UBSan catches it while it happens
- Prevent the overflow, do not detect it afterwards
- A binary search by hand
- Annex J.2: the whole list