-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should flags be represented as enums? #4
Comments
Yeah I agree that in the case of enum flags, you always have to convert to an int and back to the enum which throws type safety out the window. I'd be curious if anyone has a better idea than just raw integer types though. |
Looks like this zig proposal could be a solution: ziglang/zig#5049 It updates packed structs to specify an underlying integer type so they are compatible with the C abi. If that proposal is going to be accepted, we might be able to start transitioning to it beforehand. |
Ok I came up with one idea, I've added an const class = std.mem.zeroInit(win32.WNDCLASSEXA, .{
.style = win32.WNDCLASS_STYLES.initFlags(.{.HREDRAW = 1, .VREDRAW = 1, .OWNDC = 1});
}); Full API diff for this change is here: marlersoft/zigwin32@89203c6#diff-bd4f828bddb85d1324457f27ad66278624ef2539c5036de4c596d3b15a695820R3458 It affected 11,500 lines! |
@marler8997 Ok that seems like a decent solution for now. I like the idea of integer-backed packed structs though. Here's at least one case that your solution doesn't handle:
|
@xtian good catch. I've created an issue with the win32metadata project here: microsoft/win32metadata#507 |
Just did a new zigwin32 release. Looks like |
So how do you check if a flag exist? |
zigwin32 has moved on to using packed structs to represent flags which are very nice to use, so this issue should be addressed now. |
Regarding this TODO:
zigwin32gen/src/genzig.zig
Line 1669 in b42acec
Is there a big benefit to representing these values as non-exhaustive enums? My impression is that the common case is combining multiple bitmask values together which is awkward with the current setup. For example:
The text was updated successfully, but these errors were encountered: