Checkpoint: Observable Behavior Only
Challenge on lesson: Checkpoint: The Optimizer's Contract
CHALLENGE
Difficulty: advanced+25 XP
A static int g_seen = 0; is already in your editor. Implement three functions:
1. int pure_compute(int x) returning x * 3 + 1, locals only, no globals touched.
2. void observe(int x) storing pure_compute(x)'s result into g_seen.\n3. int lifetime_alive(int v) creating an automatic int, assigning v, and returning its value read back through a pointer taken while the object is alive.\n \npure_compute must remain side-effect free; observe is the only thing making the computation observable.
Press Submit to check your solution.
Back to lesson: Checkpoint: The Optimizer's Contract