Skip to content

Commit

Permalink
source file
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Sep 4, 2024
1 parent c65b004 commit 5ded293
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions course/code/14/struct.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 5ded293

Please sign in to comment.