#Help with casting array literal to slice

1 messages · Page 1 of 1 (latest)

fleet marten
#

I think the error messages do a pretty good job of explaining my issue:

src\main.zig:163:33: error: expected type '[]f32', found '*const [4]f32'
    const tIdx = e.x(2, 2, &[_]f32{1.0,2.0,3.0,4.0});
                                ^~~~~~~~~~~~~~~~~~~~~~~~
src\main.zig:163:33: note: cast discards const qualifier
src\main.zig:29:67: note: parameter type declared here
    pub fn x(self: *Engine, cols: usize, rows: usize, elems: []f32) XIdx {

I'd like to keep it so that e.x can be called as it is in the first error message (the main.zig:163:33 one), for the sake of a nice api. So what I'm asking is what I need to change the x signature to, but I also don't understand why const [4]f32, cant just be converted to a slice.

dry oxide
#

it expects a mutable slice but you're passing a constant one

#

does e.x actually need to mutate the slice passed in? if not change its parameter to []const f32

#

otherwise you can make a local var with that array and pass its address into e.x