authorgravatar for dev@doubly.soDevin Bayer <dev@doubly.so> 2021-04-13 14:53:44+02:00
committergravatar for dev@doubly.soDevin Bayer <dev@doubly.so> 2021-04-13 14:53:44+02:00
logca3aa02206edef4481c6f24506bfbd3b4f18fe58
tree131d4b760cf1f2d666f94e80df69402b23aee900
parenta5bbc66f10339cb2e17ef996ef097b696980595a

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" {...@@ -2763,9 +2763,24 @@ test "overaligned pointer to packed struct" {
2763 cause the test suite to fail, notifying the bug fixer to update these docs.2763 cause the test suite to fail, notifying the bug fixer to update these docs.
2764 </p>2764 </p>
2765 <p>2765 <p>
2766 It's also2766 It's also possible to set alignment of struct fields:
2767 <a href="https://github.com/ziglang/zig/issues/1512">planned to be able to set alignment of struct fields</a>.
2768 </p>2767 </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#}
2769 <p>2784 <p>
2770 Using packed structs with {#link|volatile#} is problematic, and may be a compile error in the future.2785 Using packed structs with {#link|volatile#} is problematic, and may be a compile error in the future.
2771 For details on this subscribe to2786 For details on this subscribe to