String array casting

Dear Zig experts,

Let’s say I have array of string literals.

 const str: [2][]const u8 = .{"str1", "str2"};

and in function signature I have:

fn func(arg: [][]const 8) {}

How I should call func using str?

I tried

func(&str)
func(str[0..2])

and all give compilation error.

Thanks!

[][]const u8 is a mutable slice to a unmutable slice of u8s. Since str is a const, you can not use it for a [][]const u8. If func needs to modify the contents of arg, you have to change const str to var str. If func does not need to modify the contents of arg, change to type of arg to []const []const u8.

3 Likes