byteOffsetOf add fields to non-packet struct to maintain symmetry

This commit is contained in:
vegecode 2020-07-04 11:56:19 -05:00 committed by Andrew Kelley
parent 0456b2145d
commit 2545f44db0

View File

@ -18,6 +18,8 @@ const A = struct {
e: u5, e: u5,
f: u16, f: u16,
g: u16, g: u16,
h: u9,
i: u7,
}; };
const P = packed struct { const P = packed struct {
@ -53,6 +55,8 @@ test "@byteOffsetOf" {
expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e")); expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f")); expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g")); expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
} }
test "@byteOffsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" { test "@byteOffsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" {