Hi, this is my first experience with Ziglang, so probably some kind of noob question.
With that said, I'm hacking together a shared library and have some trouble to cast the C data types probably in Zig.
I'm trying to replicate this C code
int statusengine_handle_data(int event_type, void *data){
servicecheck = (nebstruct_service_check_data *)data;
This is my Zig attempt:
pub fn handle_service_check_data(event_type: c_int, data: ?*anyopaque) callconv(.C) c_int {
var service_check = @as(?*naemon.nebstruct_service_check_data, @alignCast(data.?));
_ = event_type;
naemon.nm_log(naemon.NSLOG_RUNTIME_ERROR, "Got service check from service: '%s'!", service_check.service_description);
return 0;
}
My issue now is, that I don't find the correct syntax to cast the data: ?*anyopaque into a ?*naemon.nebstruct_service_check_data
That's my error message
src/main.zig:36:68: error: pointer element type 'anyopaque' cannot coerce into element type 'naemon.struct_nebstruct_service_check_struct'
var service_check = @as(?*naemon.nebstruct_service_check_data, @alignCast(data.?));
^~~~~~~~~~~~~~~~~~
src/naemon.zig:7879:58: note: struct declared here
pub const struct_nebstruct_service_check_struct = extern struct {
~~~~~~~^~~~~~
src/main.zig:36:68: note: use @ptrCast to cast pointer element type