| ... | ... | @@ -2763,9 +2763,24 @@ test "overaligned pointer to packed struct" { |
| 2763 | 2763 | cause the test suite to fail, notifying the bug fixer to update these docs. |
| 2764 | 2764 | </p> |
| 2765 | 2765 | <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: |
| 2768 | 2767 | </p> |
| 2768 | {#code_begin|test#} |
| 2769 | const std = @import("std"); |
| 2770 | const expectEqual = std.testing.expectEqual; |
| 2771 | |
| 2772 | test "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 | 2784 | <p> |
| 2770 | 2785 | Using packed structs with {#link|volatile#} is problematic, and may be a compile error in the future. |
| 2771 | 2786 | For details on this subscribe to |