Hi, In c/c++, I can define struct like this:
struct A
{
int a;
#if _WIN64
int b;
#endif
};
But how to do this in zig?
Hi, In c/c++, I can define struct like this:
struct A
{
int a;
#if _WIN64
int b;
#endif
};
But how to do this in zig?
Your solution idea is in std library sources.
For instance:
and welcome to ziggit.
Welcome. I think the best way to achieve that is to change the field type to void when not windows. So something like this
const A = struct {
a: i32,
b: switch (@import("builtin").os.tag) {
.windows => i32,
else => void,
},
};
another way to handle that at a higher level
const A = if (@import("builtin").os.tag == .windows)
struct {
a: i32,
b: i32,
}
else
struct {
a: i32,
};
Thank you! use void
could reduce duplicate.
Thank your reply!