From 16a794fbeef0c1d98069dc825e55af38945b5165 Mon Sep 17 00:00:00 2001 From: Justus Klausecker Date: Thu, 12 Mar 2026 22:26:04 +0100 Subject: 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. --- build.zig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 02ad592..f4b4405 100644 --- a/build.zig +++ b/build.zig @@ -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 = -- cgit v1.2.3