Accessing bool array through c pointer in 0.16

reddit had no tips so mb i’ll have better luck here getting an explanation!

i’m dicking around with converting dearzig lib to 0.16, what the heck is going on here

//pub extern fn ImGui_GetIO() [*c]ImGuiIO;
const io = imgui.ImGui_GetIO();
//do stuff to io.*.blah

all gucci until we hit

// pub const struct_ImGuiIO_t = extern struct {
// ...
//    MouseDown: [5]bool = @import("std").mem.zeroes([5]bool),
// ...

io.*.MouseDown[0] = rl.isMouseButtonDown(.left);

womp womp

raylib.zig:39:45: error: expected type '[5]bool', found 'bool'
io.*.MouseDown[0] = rl.isMouseButtonDown(.left);

but what the heck, shouldn’t i be able to access the element like that? in fact let’s see

std.debug.print("mousedown type: {}\n", .{@typeInfo(@TypeOf(io.*.MouseDown))});
std.debug.print("mousedown[0] type: {}\n", .{@typeInfo(@TypeOf(io.*.MouseDown[0]))});


mousedown type: .{ .array = .{ .len = 5, .child = bool, .sentinel_ptr = null } }
mousedown[0] type: .{ .array = .{ .len = 5, .child = bool, .sentinel_ptr = null } }

que?

now doing

var mouse_down: [5]bool = @splat(false);
mouse_down[0] = rl.isMouseButtonDown(.left);
mouse_down[1] = rl.isMouseButtonDown(.right);
mouse_down[2] = rl.isMouseButtonDown(.middle);
io.*.MouseDown = mouse_down;

works fine and typeinfo gives mouse_down[0] type: .{ .bool = void } which is what i expected from the above too.

Also on 0.15.2 it works and typeof io.*.MouseDown[0] is bool like above.

I can not reproduce this bug

1 Like