#How to read `@embedFile` as a `*const [_:0]u64`?

1 messages · Page 1 of 1 (latest)

high ibex
#

Let's say I have the following files: main.zig and foo.blob

const file /* : *const [N:0]u8 */ = @embedFile("foo.blob");
const ids: *const [N / 8]u64 = /* ... */; // (I don't need null terminator)
aaaaaaaa

Is there a faster way of defining ids then copying the data of file into a comptime array such as in this?

const file = @embedFile("foo.blob");
const ids = blk: {
    const fileU64s = std.mem.bytesAsValue(u64, file);
    var out: [fileU64s.len]u64 = undefined;

    for (fileU64s, 0..) |id, i| {
        out[i] = id;
    }

     break :blk out;
};
idle flame
#

could you just ptrcast it?

high ibex
#

no

src\overloads.zig:10:43: error: cast increases pointer alignment
    var out: *const [file.len / 8:0]u64 = @ptrCast(file);
                                          ^~~~~~~~~~~~~~
src\overloads.zig:10:52: note: '*const [8:0]u8' has alignment '1'
    var out: *const [file.len / 8:0]u64 = @ptrCast(file);
                                                   ^~~~
#

hmm it does work if I add @alignCast around that...but I'm not sure how safe that is.

#

ok it does seem to print out the write value: 0x6161616161616161

idle flame
#

my guess is its probably safe since its at comptime