Practice ยท 2 of 2
Compile-Time Contracts
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);
``
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: X-Macro & Assert Gym