mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
22 lines
416 B
Zig
22 lines
416 B
Zig
|
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 "pointers of sub-byte-aligned fields share addresses" {
|
||
|
try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b));
|
||
|
try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c));
|
||
|
}
|
||
|
|
||
|
// test
|