Practice ยท 3 of 3
Compile-Time Layout Contract
CHALLENGE
Difficulty: advanced+25 XP
ISO C11. Given struct packet { unsigned char tag; unsigned short len; unsigned int crc; }; (declared for you), implement size_t packet_min_size(void) returning sizeof(struct packet) โ it must be at least 7 (tag + len + crc with no padding can compress to 7 on some ABIs, but padding may grow it). Then int packet_layout_sane(void) returns 1 when offsetof(packet, crc) >= offsetof(packet, len) + sizeof(unsigned short) and 0 otherwise โ the members must not overlap.
Press Submit to check your solution.
Back to lesson: Practice: Portability Probes