Hi, I apologize for the stupid question but I'm new to zig and haven't done pointer arithmetic in a long time. I'm having a hard time with the type system. I have this concatenate function for strings:
`fn concatenate(comptime size1: usize, comptime str1: *const [size1]u8, comptime size2: usize, comptime str2: *const [size2]u8) []u8 {
const str1Slice = str1[0..size1];
const str2Slice = str2[0..size2];
const newStringSize = size1 + size2;
var newStringSlice: [newStringSize]u8 = undefined;
for (0..size1) |i| {
newStringSlice[i] = str1Slice[i];
}
comptime var whereWeLeftOf = size1;
for (0..size2) |i| {
newStringSlice[whereWeLeftOf] = str2Slice[i];
whereWeLeftOf += 1;
}
return &newStringSlice;
}`
And this test function:
`test "concatenation" {
const str1: *const [5]u8 = "Love ";
const str2: *const [3]u8 = "Zig";
const expectedStr: *const [8]u8 = "Love Zig";
const newString = comptime concatenate(5, str1, 3, str2);
const expectedSlice: []u8 = expectedStr[0..8];
try std.testing.expectEqual(@as([]u8, expectedSlice), newString);
}`
for this line const expectedSlice: []u8 = expectedStr[0..8]; the compiler gives me error: expected type '[]u8', found '*const [8]u8' . My question is why obviously :). I'm using the slicing operator there. More than that I'm doing the same thing on *const []u8 's in the concatenate function.
Thanks in advance and sorry for the stupid question again 🙂