Skip to content
This repository was archived by the owner on Jun 8, 2025. It is now read-only.

Commit 2452cce

Browse files
committed
Add labo
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
1 parent 2599309 commit 2452cce

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

labo/basic/structfieldsiterate.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const std = @import("std");
2+
3+
// https://gist.github.com/travisstaloch/71a7a2bc260997abe06016c619b40bf2
4+
pub fn main() !void {
5+
const U1s = packed struct {
6+
a: u1,
7+
b: u1,
8+
c: u1,
9+
};
10+
11+
const x = U1s{ .a = 1, .b = 0, .c = 0 };
12+
inline for (std.meta.fields(@TypeOf(x))) |f| {
13+
std.debug.print(f.name ++ " {}\n", .{@as(f.field_type, @field(x, f.name))});
14+
}
15+
}

0 commit comments

Comments
 (0)