Zig Version 0.13.0 Steps to Reproduce and Observed Behavior This fails: const Request = packed struct { endianness: u8, pad1: u8, major_version: u16, minor_version: u16, authorization_len: u16, authorization_data_len: u16, pad2: u16, }; comptime std.debug.assert(@sizeOf(Request) ==...
@@ -203,7 +203,7 @@ zig 在使用结构体的时候还支持省略结构体类型,只要能让 zig ::: 4. 默认情况下 zig 还会对字段进行重新排序,但是在 packed 下并不会重新排序。 4. `packed struct` 会保证字段的顺序以及在字段间不存在额外的填充,但针对结构体本身可能仍然存在额外的填充: :::details 示例 @@ ...
const std = @import("std"); const assert = std.debug.assert; const expect = std.testing.expect; const S = packed struct(u16) { x: u15 = 0, y: u1 = 0, }; fn foo(s: S) callconv(.C) i32 { return s.x; } test "example" { var s: S = .{}; s.x +...
Intended toclose#12960 I did a quick grep of this entire repo and every usage ofreadStructis using anexternstruct. Here's an alternative that should handle (ignore) byte-sized padding as well, for discussion: pubfnreadStruct(self:Self,comptimeT:type)anyerror!T{constsize_bytes=@divExact(@...
View details Luukdegram merged commit 320c4d6 into ziglang:master Feb 11, 2024 10 checks passed Member andrewrk commented Feb 11, 2024 Nice! Luukdegram deleted the issue-18894 branch February 12, 2024 06:52 Sign up for free to join this conversation on GitHub. Already have an accoun...