Skip to content

Update doc for struct field alignment. #8518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -2763,9 +2763,24 @@ test "overaligned pointer to packed struct" {
cause the test suite to fail, notifying the bug fixer to update these docs.
</p>
<p>
It's also
<a href="https://github.com/ziglang/zig/issues/1512">planned to be able to set alignment of struct fields</a>.
It's also possible to set alignment of struct fields:
</p>
{#code_begin|test#}
const std = @import("std");
const expectEqual = std.testing.expectEqual;

test "aligned struct fields" {
const S = struct {
a: u32 align(2),
b: u32 align(64),
};
var foo = S{ .a = 1, .b = 2 };

expectEqual(64, @alignOf(S));
expectEqual(*align(2) u32, @TypeOf(&foo.a));
expectEqual(*align(64) u32, @TypeOf(&foo.b));
}
{#code_end#}
<p>
Using packed structs with {#link|volatile#} is problematic, and may be a compile error in the future.
For details on this subscribe to
Expand Down