I agree think the wording/example is not quite right. Also it says “pointers” can change the alignment, but what’s really changing the alignment in the example is the local itself.
Maybe should be more like…
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const S = packed struct {
a: u32,
b: u32,
};
test "underaligned pointer to packed struct" {
var foo: S = .{ .a = 1, .b = 2 };
const ptr: *align(4) S = &foo;
const ptr_to_b = &ptr.b;
try expectEqual(2, ptr_to_b.*);
}
Or even throw an align(16) on the local to drive the point home that you can change the alignment of a packed struct.