Suppose there is the following Zig function
fn foo(comptime T: type, slice: []T) void {}
How is slice actually passed to foo in memory here?
Since slices in Zig are essentially pairs of a pointer and a length, I suppose slice’s type is internally similar to the struct
struct {
buffer: [*]T,
len: usize,
}
What I don’t know is how this struct is actually passed to foo. Are the two struct members passed to foo directly, i.e., foo is then equivalent to the following C snippet
void foo(T[] buffer, size_t len) {}
or are they passed indirectly to foo through a pointer pointing to the actual slice object, i.e., the equivalent C snippet is then
struct slice {
T[] buffer;
size_t len;
}
void foo(struct slice *slice) {
T[] buffer = slice->buffer;
size_t len = size->len;
}
instead?