diff --git a/doc/langref.html.in b/doc/langref.html.in index e87decdf4a9ab51de65bc8ae0c8d6a8378b47dcd..643c948b68e99e11236f9c24e180af848736a820 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2103,8 +2103,9 @@ or less than {#syntax#}1 << 29{#endsyntax#}.

- In Zig, a pointer type has an alignment value. If the value is equal to the - alignment of the underlying type, it can be omitted from the type: + Pointer types may explicitly specify an alignment in bytes. If it is not + specified, the alignment is assumed to be equal to the alignment of the + underlying type.

{#code|test_variable_alignment.zig#} diff --git a/doc/langref/test_comptime_invalid_error_code.zig b/doc/langref/test_comptime_invalid_error_code.zig index ebc6314764b399fcbbb5a1b03225e4d9611f5f21..e4fedf5812a972af6168e26c7689de92a204165c 100644 --- a/doc/langref/test_comptime_invalid_error_code.zig +++ b/doc/langref/test_comptime_invalid_error_code.zig @@ -1,8 +1,5 @@ comptime { - const err = error.AnError; - const number = @intFromError(err) + 10; - const invalid_err = @errorFromInt(number); - _ = invalid_err; + _ = @errorFromInt(12345); } -// test_error=integer value '11' represents no error +// test_error=integer value '12345' represents no error diff --git a/doc/langref/test_missized_packed_struct.zig b/doc/langref/test_missized_packed_struct.zig index 791f97cc311b6f33b5859e1612c684cde6d0d6c3..df323244d4bebdf34dd6dde9bdbdfe6d8720dfd2 100644 --- a/doc/langref/test_missized_packed_struct.zig +++ b/doc/langref/test_missized_packed_struct.zig @@ -3,4 +3,4 @@ test "missized packed struct" { _ = S{ .a = 4, .b = 2 }; } -// test_error=backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 24 +// test_error=backing integer bit width does not match total bit width of fields diff --git a/doc/langref/test_variable_alignment.zig b/doc/langref/test_variable_alignment.zig index 01768e29eb0e81d5924644fbbbbd6739047fb690..d0a4560fa2954930d7d2f460c2d74d6b64b0d3cf 100644 --- a/doc/langref/test_variable_alignment.zig +++ b/doc/langref/test_variable_alignment.zig @@ -1,15 +1,20 @@ 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; - const align_of_i32 = @alignOf(@TypeOf(x)); + try expectEqual(*i32, @TypeOf(&x)); - try expectEqual(*align(align_of_i32) i32, *i32); - if (builtin.target.cpu.arch == .x86_64) { - try expectEqual(4, @typeInfo(*i32).pointer.alignment); - } + + 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