diff --git a/course/code/14/struct.zig b/course/code/14/struct.zig index cdab3de3..ac3ba77e 100644 --- a/course/code/14/struct.zig +++ b/course/code/14/struct.zig @@ -363,3 +363,21 @@ const PackedCast = struct { } // #endregion packed_cast }; + +const aligned_struct = struct { + // #region aligned_struct + const std = @import("std"); + const expect = std.testing.expect; + + const S = packed struct { + a: u32, + b: u32, + }; + test "overaligned pointer to packed struct" { + var foo: S align(4) = .{ .a = 1, .b = 2 }; + const ptr: *align(4) S = &foo; + const ptr_to_b: *u32 = &ptr.b; + try expect(ptr_to_b.* == 2); + } + // #endregion aligned_struct +}; \ No newline at end of file