authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2021-04-14 10:56:37+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-04-14 10:56:37+02:00
log1fada3746606b3a83d4c56213de93a1017753c96
tree9ec0b7f4057d0bc3068e0c1f7076d86d3264c36c
parente761e0ac18aa1eab22b9547d702067910ed82c4a
parentca3aa02206edef4481c6f24506bfbd3b4f18fe58
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #8518 from akvadrako/doc-field-align

Update doc for struct field alignment.

1 files changed, 17 insertions(+), 2 deletions(-)

doc/langref.html.in+17-2
......@@ -2763,9 +2763,24 @@ test "overaligned pointer to packed struct" {
27632763 cause the test suite to fail, notifying the bug fixer to update these docs.
27642764 </p>
27652765 <p>
2766 It's also
2767 <a href="https://github.com/ziglang/zig/issues/1512">planned to be able to set alignment of struct fields</a>.
2766 It's also possible to set alignment of struct fields:
27682767 </p>
2768 {#code_begin|test#}
2769const std = @import("std");
2770const expectEqual = std.testing.expectEqual;
2771
2772test "aligned struct fields" {
2773 const S = struct {
2774 a: u32 align(2),
2775 b: u32 align(64),
2776 };
2777 var foo = S{ .a = 1, .b = 2 };
2778
2779 expectEqual(64, @alignOf(S));
2780 expectEqual(*align(2) u32, @TypeOf(&foo.a));
2781 expectEqual(*align(64) u32, @TypeOf(&foo.b));
2782}
2783 {#code_end#}
27692784 <p>
27702785 Using packed structs with {#link|volatile#} is problematic, and may be a compile error in the future.
27712786 For details on this subscribe to