| 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 3 | const expect = std.testing.expect; |
| 4 | const expectEqual = std.testing.expectEqual; |
| 5 | |
| 6 | test "variable alignment" { |
| 7 | var x: i32 = 1234; |
| 8 | |
| 9 | try expectEqual(*i32, @TypeOf(&x)); |
| 10 | |
| 11 | try expect(@intFromPtr(&x) % @alignOf(i32) == 0); |
| 12 | |
| 13 | // The implicitly-aligned pointer can be coerced to be explicitly-aligned to |
| 14 | // the alignment of the underlying type `i32`: |
| 15 | const ptr: *align(@alignOf(i32)) i32 = &x; |
| 16 | |
| 17 | try expectEqual(1234, ptr.*); |
| 18 | } |
| 19 | |
| 20 | // test |