I'm trying to use a small C library (kthread, link below) which has a parallel for loop construct, and takes a function pointer as argument. Is there a way to make Zig function pointers work with the C counter part easily?
const std = @import("std");
// https://github.com/lh3/minimap2/blob/master/kthread.[hc]
const c = @cImport({
@cInclude("kthread.h");
});
fn worker_fun(data: *anyopaque, i: c_long, tid: c_int) void {
_ = tid;
_ = data;
std.debug.print("ok computer {d}\n", .{i});
}
pub fn main() !void {
// void kt_for(int n_threads, void (*func)(void*,long,int), void *data, long n);
c.kt_for(8, &worker_fun, .{}, 100);
}
With this code I'm getting the compilation error:
par.zig:16:17: error: expected type '?*const fn (?*anyopaque, c_long, c_int) callconv(.C) void', found '*const fn (*anyopaque, c_long, c_int) void'
c.kt_for(8, &worker_fun, .{}, 100);
^~~~~~~~~~~
Thanks.