#Help explaining anonymous struct literal syntax
1 messages · Page 1 of 1 (latest)
You may recognize this pattern from arrays where you can write var a = [3]f32{...} which is equivalent to var a: [3]f32 = .{...}
The empty {} means that we use the default values for all fields in std.heap.GeneralPurposeAllocator
The .{…} syntax inprint is a Tuple, basically an anonymous struct with numerical indices and a .len property
Additionally, zig doesn't really like vaArgs and only supports it because of C (I think)
So the standard way to do an unknown number of arguments is to pass a tuple and then do some comptime iteration over it
thanks so much! The {} at the end to instantiate finally makes sense. I've seen that everywhere (including Go)
Thanks @keen tapir - Zig tuples are now my favorite tuples. Them supporting ++ is great:
const values = .{
@as(u32, 1234),
@as(f64, 12.34),
true,
"hi",
} ++ .{false} ** 2;
Yeah, I like that ++ and ** do what you expect them to do 
what does ** do?
repeat a tuple or array n times
i screwed somethign up and can't react now 😦
Just to add on to that: Zig tuples are designed to generally be fairly interchangable with arrays. ** and ++ are sort of made to be used on arrays (and slices), but Zig tries to make arrays like [3]u32 act similarly to the equivalent tuple, in this case struct { u32, u32, u32 }. (btw, in case you weren't aware, that's the syntax to explicitly declare a tuple type if you ever need to)
Anyways, afaict deleting the original post makes it impossible to react to threads, which is a bit silly... <@&761628228409884672>, could one of y'all manually close this one?
lmao mobile ui is shit, can't close 
done 🙂
ahh stop chatting after closing