How to get @sizeOf(tuple)

why @sizeOf(tuple) is 0?

test "size of tuple" {
    std.debug.print("size = {d}\n", .{@sizeOf(@TypeOf(.{100}))});
}

this get size = 0

This is because the tuple .{100} is compile-time known, all compile-time known values are zero sized. Try this:

test "size of tuple" {
    var a: usize = 100;
    std.debug.print("size = {d}\n", .{@sizeOf(@TypeOf(.{a}))});
}
1 Like