| author | |
| committer | |
| log | 34d780f4bbefa8344cae5da49fe84bed83d8274f |
| tree | 9764659edc6d7e5d8bf9b12db679a6bb5cf3be4a |
| parent | ce1f28a7497903cf00431d6976c162c37683232a |
| signature |
4 files changed, 16 insertions(+), 13 deletions(-)
doc/langref.html.in+3-2| ... | ... | @@ -2103,8 +2103,9 @@ or |
| 2103 | 2103 | less than {#syntax#}1 << 29{#endsyntax#}. |
| 2104 | 2104 | </p> |
| 2105 | 2105 | <p> |
| 2106 | In Zig, a pointer type has an alignment value. If the value is equal to the | |
| 2107 | alignment of the underlying type, it can be omitted from the type: | |
| 2106 | Pointer types may explicitly specify an alignment in bytes. If it is not | |
| 2107 | specified, the alignment is assumed to be equal to the alignment of the | |
| 2108 | underlying type. | |
| 2108 | 2109 | </p> |
| 2109 | 2110 | {#code|test_variable_alignment.zig#} |
| 2110 | 2111 |
doc/langref/test_comptime_invalid_error_code.zig+2-5| ... | ... | @@ -1,8 +1,5 @@ |
| 1 | 1 | comptime { |
| 2 | const err = error.AnError; | |
| 3 | const number = @intFromError(err) + 10; | |
| 4 | const invalid_err = @errorFromInt(number); | |
| 5 | _ = invalid_err; | |
| 2 | _ = @errorFromInt(12345); | |
| 6 | 3 | } |
| 7 | 4 | |
| 8 | // test_error=integer value '11' represents no error | |
| 5 | // test_error=integer value '12345' represents no error |
doc/langref/test_missized_packed_struct.zig+1-1| ... | ... | @@ -3,4 +3,4 @@ test "missized packed struct" { |
| 3 | 3 | _ = S{ .a = 4, .b = 2 }; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | // test_error=backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 24 | |
| 6 | // test_error=backing integer bit width does not match total bit width of fields |
doc/langref/test_variable_alignment.zig+10-5| ... | ... | @@ -1,15 +1,20 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const expect = std.testing.expect; | |
| 3 | 4 | const expectEqual = std.testing.expectEqual; |
| 4 | 5 | |
| 5 | 6 | test "variable alignment" { |
| 6 | 7 | var x: i32 = 1234; |
| 7 | const align_of_i32 = @alignOf(@TypeOf(x)); | |
| 8 | ||
| 8 | 9 | try expectEqual(*i32, @TypeOf(&x)); |
| 9 | try expectEqual(*align(align_of_i32) i32, *i32); | |
| 10 | if (builtin.target.cpu.arch == .x86_64) { | |
| 11 | try expectEqual(4, @typeInfo(*i32).pointer.alignment); | |
| 12 | } | |
| 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.*); | |
| 13 | 18 | } |
| 14 | 19 | |
| 15 | 20 | // test |