Skip to main content

Practice ยท 2 of 2

Shrink by Reordering

The boilerplate defines a wasteful struct and a mirror: ``c struct Naive { char a; double d; char b; long l; }; struct Tight { double d; long l; char a; char b; }; ` Implement: `c /* 1 if Tight is strictly smaller than Naive, else 0 */ int tight_is_smaller(void); /* bytes wasted by padding inside a struct of size total with raw member bytes raw */ size_t padding_bytes(size_t total, size_t raw); /* size of an array of n Tight structs */ size_t tight_array_bytes(size_t n); ``

Difficulty: intermediate

Back to lesson: Practice: Layout Gym