Module 8 · Recursion
Under the Hood: Stack Frames, Tail Calls and Stack Overflow
ProReading
Kenji ran lesson 2's probe with the input 10000000. On the Playground it succeeded, ten million calls deep, in 104,592 KB of memory. His friend David built the same file on a Linux laptop with a plain gcc dive.c. Same input, one line back: Segmentation fault.
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 Under the Hood: Stack Frames, Tail Calls and Stack Overflow
- Where the stack lives, and where it ends
- The guard region and the signal: what a stack overflow is
- One crash, three names
- A tail call leaves nothing to do after the call
- Why n * factorial(n - 1) is not a tail call
- What GCC 12 does with both at -O2
- Switch the rewrite off, and the calls come back
- Work left after the call keeps the call
- The limit is a setting, and some machines have almost none