#embedFile requires known size?

1 messages · Page 1 of 1 (latest)

delicate vector
#

I'm trying to use @embedFile at comptime: https://ziglang.org/documentation/master/#toc-embedFile.

fn js_load_file() *const [*:0]u8 {
    const contents = @embedFile("./foo.js");
    return contents;
}```

I get the following
                ^

./src/main.zig:341:12: note: pointer type child '[55:0]u8' cannot cast into pointer type child '[*:0]u8'
return contents;
^

Do I have to know the length of the file in order to use this function?
drifting tapir
#

I think you want [*:0]const u8 not *const [*:0]u8

delicate vector
#

Thank you! Are you able to provide an explanation? The docs say that @embedFile returns *const [N:0]u8

#

That's a const pointer to a slice of N u8's terminated with a 0 right?

drifting tapir
#

Yep

#

Which implicitly coerces to [:0]const u8 (null terminated slice of const u8)

#

As well as [*:0]const u8 (multi-pointer to null-terminated array of u8)

delicate vector
#

is there somewhere to read about this implicit coersion?

drifting tapir
#

It's probably in the docs

simple light
drifting tapir
#

Oops yes, missed that