diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-04-24 17:41:47 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-04-25 00:09:24 -0700 |
| commit | 1b90888f576b4863f4a61213a9ca32b97aa57859 (patch) | |
| tree | ecf4d98a6b296b9aa36fd0c20a729413862f6b91 /doc/langref/test_misaligned_pointer.zig | |
| parent | 9d64332a5959b4955fe1a1eac793b48932b4a8a8 (diff) | |
| download | zig-1b90888f576b4863f4a61213a9ca32b97aa57859.tar.gz zig-1b90888f576b4863f4a61213a9ca32b97aa57859.zip | |
migrate langref documentation generation to the build system
Diffstat (limited to 'doc/langref/test_misaligned_pointer.zig')
| -rw-r--r-- | doc/langref/test_misaligned_pointer.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/langref/test_misaligned_pointer.zig b/doc/langref/test_misaligned_pointer.zig new file mode 100644 index 0000000000..11795ce090 --- /dev/null +++ b/doc/langref/test_misaligned_pointer.zig @@ -0,0 +1,24 @@ +const std = @import("std"); +const expect = std.testing.expect; + +const BitField = packed struct { + a: u3, + b: u3, + c: u2, +}; + +var bit_field = BitField{ + .a = 1, + .b = 2, + .c = 3, +}; + +test "pointer to non-byte-aligned field" { + try expect(bar(&bit_field.b) == 2); +} + +fn bar(x: *const u3) u3 { + return x.*; +} + +// test_error=expected type |
