mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
21 lines
518 B
Zig
21 lines
518 B
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const expect = std.testing.expect;
|
|
const expectEqual = std.testing.expectEqual;
|
|
|
|
test "variable alignment" {
|
|
var x: i32 = 1234;
|
|
|
|
try expectEqual(*i32, @TypeOf(&x));
|
|
|
|
try expect(@intFromPtr(&x) % @alignOf(i32) == 0);
|
|
|
|
// The implicitly-aligned pointer can be coerced to be explicitly-aligned to
|
|
// the alignment of the underlying type `i32`:
|
|
const ptr: *align(@alignOf(i32)) i32 = &x;
|
|
|
|
try expectEqual(1234, ptr.*);
|
|
}
|
|
|
|
// test
|