Skip to main content

Practice · 2 of 2

Compile-Time Contracts

CHALLENGE
Difficulty: intermediate+25 XP

The boilerplate contains _Static_asserts your code must not violate — and functions that RELY on them. Implement: ``c /* packs two nibbles into a byte — relies on the static assert that unsigned char is exactly 8 bits */ unsigned char pack_nibbles(unsigned lo, unsigned hi); /* returns the table capacity; the static assert guarantees it is a power of two, so capacity-1 is a mask */ size_t tab_mask(void); /* returns 1 if v is a power of two (v > 0), using the bit trick */ int is_pow2(size_t v); ``

Back to lesson: Practice: X-Macro & Assert Gym