mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
23 lines
526 B
Zig
23 lines
526 B
Zig
|
const std = @import("std");
|
||
|
const expect = std.testing.expect;
|
||
|
|
||
|
const BitField = packed struct {
|
||
|
a: u3,
|
||
|
b: u3,
|
||
|
c: u2,
|
||
|
};
|
||
|
|
||
|
test "offsets of non-byte-aligned fields" {
|
||
|
comptime {
|
||
|
try expect(@bitOffsetOf(BitField, "a") == 0);
|
||
|
try expect(@bitOffsetOf(BitField, "b") == 3);
|
||
|
try expect(@bitOffsetOf(BitField, "c") == 6);
|
||
|
|
||
|
try expect(@offsetOf(BitField, "a") == 0);
|
||
|
try expect(@offsetOf(BitField, "b") == 0);
|
||
|
try expect(@offsetOf(BitField, "c") == 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// test
|