Hi all,
I'm new to Zig, switching over from C. I have a project setup which uses Zig 0.13.0 and @cImport to use SDL 3.1.6. I started to do some basic input handling functions when I ran into an error I don't understand.
SDL is imported with this:
const c = @cImport({
@cInclude("SDL3/SDL.h");
});
Here is a snippet from my main function where I get the error:
var event: c.SDL_Event = undefined;
while (c.SDL_PollEvent(&event)) {
input.handleEvent(event);
}
The definition of handleEvent from input.zig:
pub fn handleEvent(event: c.SDL_Event) void {}
I get this error I don't understand:
src\main.zig:29:35: error: expected type 'cimport.union_SDL_Event', found 'cimport.union_SDL_Event'
input.handleEvent(event);
^~~~~
E:\zage\.zig-cache\o\...\cimport.zig:4139:36: note: union declared here
pub const union_SDL_Event = extern union {
~~~~~~~^~~~~
E:\zage\.zig-cache\o\...\cimport.zig:3854:36: note: union declared here
pub const union_SDL_Event = extern union {
~~~~~~~^~~~~
src\input.zig:33:28: note: parameter type declared here
pub fn handleEvent(event: c.SDL_Event) void {
~^~~~~~~~~~
It seems like the types are the same, right? I also tried passing in the event by pointer:
// input.zig:
pub fn handleEvent(event: [*c]c.SDL_Event) void {}
// main.zig:
var event: c.SDL_Event = undefined;
while (c.SDL_PollEvent(&event)) {
input.handleEvent(&event);
}
Similar error:
src\main.zig:29:35: error: expected type '[*c]cimport.union_SDL_Event', found '*cimport.union_SDL_Event'
input.handleEvent(&event);
^~~~~~
src\main.zig:29:35: note: pointer type child 'cimport.union_SDL_Event' cannot cast into pointer type child 'cimport.union_SDL_Event'
What am I doing wrong? And what should I do instead? Any help is appreciated.