#initialize array with arrays
1 messages · Page 1 of 1 (latest)
you probably want something like```ts
const do_big_thing = doThing1() ++ doThing2() ++ .{Data_t{}};
It keeps not like it.
error: expected type 'Data_t', found '[5]Data_t'
}) ++
^~
right at the end when appending to the last thingy.
please do share more of the surrounding code, as well as relevent functions' signatures
const Data_t = u8;
const std = @import("std");
pub fn doThing1() [2]Data_t {
return .{ 1, 2 };
}
var OPERATIONS = [_]Data_t{
.{} ++ doThing1(),
};
test "thing" {
for (OPERATIONS) |i| {
std.debug.print("{i} ", .{i});
}
}
I think you misunderstand the meaning of the ++ operator. as the two operands, it takes arrays of a certain type, and then outputs a concatenation of the arrays (the same can be done with pointers-to-arrays, or slices, to get a pointer-to-array or slice result resp.)
the expression .{} ++ doThing1() then already gives you an array of Data_ts (I'm not sure if Zig copes with the .{} over there, but that's besides the pointer) - you're then trying to use that Data_t... as an element of a Data_t array!
I see the errors of my way.