Skip to main content

Practice ยท 2 of 3

_Generic Front Door

CHALLENGE
Difficulty: advanced+25 XP

Implement const char *describe(value_t v) over a tagged union typedef struct { unsigned char tag; union { long i; double d; } as; } value_t; with tags 1 = long, 2 = double: return 'long' or 'double' for the live arm. Then implement long long to_int(long long x) (identity) โ€” and note in the test that a _Generic macro selects the *type* of its argument at compile time, which is how C keeps type-safety at such doors without overloads.

Back to lesson: Practice: Generic Mechanism Drills