#"cast discards const qualifier" error... even when it doesn't.

1 messages · Page 1 of 1 (latest)

lapis pecan
#

I have the following function signature:

fn medianCut(
    allocator: std.mem.Allocator,
    partitions: std.ArrayList([]u32),
    pixels: []u32,
    depth: u8,
) !void { .... }

Inside this function, I do: partitions.append(...).

And even though the parameter type is clearly non-cost, I get an error saying:

sick harness
#

partitions needs to be a *std.ArrayList([]u32)

#

function parameters are always const in zig

lapis pecan
#

Thanks, If I do that, I get an error at the call site:

#

Even though the call is straightforward:


    var partitions = std.ArrayList([]u32).init(allocator);
    defer partitions.deinit(allocator);
    try medianCut(allocator, &partitions, pixels, 2);

sick harness
#

is the error saying it found *const *?

#

🤔

lapis pecan
sick harness
lapis pecan
sick harness
#

does medianCut do recursion?

lapis pecan
#

Yep!

sick harness
#

are you passing the address of the arraylist inside medianCut? if so thats the problem

lapis pecan
#

Wow

#

how did you guess that xD

sick harness
#

partitions is already a pointer inside the function

lapis pecan
#

yes you were right

sick harness