111/112: Add exercises for packed structs/unions

The first exercise introduces the `packed` keyword as an alternative for
bitwise operations. Its main goals are establishing a solid understanding
of field order and conveying the fact that packed containers are basically
integers.
It introduces the concept of container layouts and briefly explains the
default `auto` layout before introducing the `packed` layout (but doesn't
touch `extern` at all).
The exercise also presents a real-world use case for packed containers,
namely LZ4 frame descriptors.
Furthermore it covers equality comparisons between packed containers.

The second exercise talks about switch statements with packed containers
and goes into some more detail on packed unions.
This commit is contained in:
Justus Klausecker
2026-03-12 22:26:04 +01:00
parent 973ec41097
commit 16a794fbee
5 changed files with 350 additions and 0 deletions

View File

@@ -1308,6 +1308,14 @@ const exercises = [_]Exercise{
\\& 1110 // (bitmask)
\\= 0110
},
.{
.main_file = "111_packed.zig",
.output = "",
},
.{
.main_file = "112_packed2.zig",
.output = "",
},
.{
.main_file = "999_the_end.zig",
.output =