I suspect I am doing something completely wrong because this is the first time I am trying to use meta-programming in zig.
Here is the entire loop for context, the if (@field == @field) check does work, the issue is its true when both values are 0 or 1 and I only care about when they are both 1. I can’t seem to figure out how to add this check. Anytime I try and actually compare the returned number from @field with an integer it fails to compile, considering that is what is shown in stdout when printing it I don’t really get why that is.
if (opts.required_features12 != null) {
inline for (std.meta.fields(c.VkPhysicalDeviceVulkan12Features)) |feature| {
if (@field(opts.required_features12.?.*, feature.name) == @field(features12, feature.name)) {
const num = @field(opts.required_features12.?.*, feature.name);
std.debug.print("was it equal to 1: {any}\n", .{num == 1});
}
}
}
// COMPILE ERROR
src/vulkan_init.zig:368:69: error: incompatible types: '?*anyopaque' and 'comptime_int'
std.debug.print("was it equal to 1: {any}\n", .{num == 1});
~~~~^~~~
what really confuses me is if I to then explicitly make num a ?*anyopaque it fails to compile.
// COMPILE ERROR
src/vulkan_init.zig:365:42: error: expected type '?*anyopaque', found 'c_uint'
const num: ?*anyopaque = @field(opts.required_features12.?.*, feature.name);
It then tells me it is of type c_uint, so I change num to be that type and it switches to saying its actually ?*anyopaque.
// COMPILE ERROR
src/vulkan_init.zig:365:37: error: expected type 'c_uint', found '?*anyopaque'
const num: c_uint = @field(opts.required_features12.?.*, feature.name);
If I use no explicit type on num and just keep it as const num = … it actually tells me it is type u32 when I do @TypeOf on it.
std.debug.print("@TypeOf(num): {any}\n", .{@TypeOf(num)});
/// RESULT IN STDOUT
@TypeOf(num): u32
But even then, if i try and make num a u32 ahead of time it also fails.
// COMPILE ERROR
src/vulkan_init.zig:365:34: error: expected type 'u32', found '?*anyopaque'
const num: u32 = @field(opts.required_features12.?.*, feature.name);