Files
zig/doc/langref/test_variable_alignment.zig
T
2026-03-10 10:38:50 +00:00

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