Array of arrays with default value, dont specify length

Hi,
Im having trouble with initializing an array of strings

pub const Foo = struct {
    bar: []const u8 = "this works ofc",
    foo: [][]const u8 = .{"this", "fails"},
};

I want a pointer anyway but

pub const Foo = struct {
    foo: *const [][]const u8 = &.{"this", "fails"},
};
const foo = [_][]const u8{"this", "fails"};

pub const Foo = struct {
    foo: *const [][]const u8 = &foo,
};

well im trying for foo to hold an slice, so lets pass an slice since it cant do the casting itself

const foo = [_][]const u8{"this", "fails"};

pub const Foo = struct {
    foo: *const [][]const u8 = foo[0..],
};

It wants me to specify foo: *const [2][] const u8, even for the pointer, even for the slice
(i specially dont understand this part, isnt []...supposed to be the syntax for a slice? why does it want me to specify the array length? then it wouldn be a slice??)

but later the contents of foo may change and may want to hold other number of items.
what am i missing? is it in my understanding of arrays and slices?

thanks in advanced

This is happens at comptime and everything is constant you need to do it like this:

const std = @import("std");

fn bar(s: []const []const u8) void {
    for (s) |val| {
        std.debug.print("{s} ", .{val});
    }
    std.debug.print("\n", .{});
}

pub fn main() !void {
    const foo: []const []const u8 = &.{ "this", "succeeds" };
    std.debug.print("{s} {s}\n", .{ foo[0], foo[1] });
    bar(foo);
    bar(&.{ "this", "also", "succeeds" });
}

Please note the second const.

In general the difference between a slice and an array is that the length of the array must be known at compile time. The length for a slice is generally not known at compile time. The zig compiler is generally quite strict. So when you try to declare a slice at compile time that has a known length it basically asks you if really want it to be a slice or an array.

Also note that in this case the slices point to constant memory, so they are basically an array.

i see, indeed adding that const works, but i dont think i understand why that is. seems like magic specially since i dont actually intend for it to be a const. But it works, and i can overwrite it like a var too. So whats the const doing?