Skip to main content

Practice · 1 of 4

Parenthesize or Perish

CHALLENGE
Difficulty: advanced+25 XP

Implement three macros and prove their expansion: ``c #define SQ(x) ((x) * (x)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define STR(x) STR_(x) ` Then implement int sq_trap(void) returning the value of SQ(1 + 2) (9, not 1 + 2*1 + 2 = 5), int max_side(void)` computing MAX(i++, 5) is forbidden — instead demonstrate the double-evaluation hazard by returning what MAX(a, b) computes for a=3, b=3 when the expression contains a function call counter (implement it safely: call once, store, compare).

Back to lesson: Practice: Preprocessor Mechanics Drills