-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Trouble using C enums #3472
Comments
reproducable example: test.h enum MyEnum {
MyEnum_A = 1,
MyEnum_B = 2,
};
struct MyStruct {
enum MyEnum theEnum;
}; test.zig
error:
|
Shouldn't it be |
@giann then I get:
|
the C wrapper I am importing shipped with this hack:
so at the moment I am leaving that in place and wrapping the enum values in |
@andrewrk: I don't think the translate-c label is correct, I am |
|
The smaller example that you provided works fine, you are just incorrectly initializing the struct, and the error messages are not telling you that. Correct test.zig file:
Edit: I think there should be a compile error telling you that you are trying to use the function call syntax on a struct type. |
ah, thanks for the clarification!
the enum type is inlined in the struct, so while the two structs are identical they are different nominal types and so the error messages above can be explained.
the error can be reproduced in my full repo by modifying struct ImGuiIO
{
- ImGuiConfigFlags ConfigFlags;
+ enum ImGuiConfigFlags_ ConfigFlags;
ImGuiBackendFlags BackendFlags;
ImVec2 DisplaySize; (this breaks the build, but with |
The
I had to add a |
@FireFox317 I have been doing that define in Are you sure that you are not using it using the
(not sure about order in the file, I'm just jumping back and forth). The patch is to actually use the enum type in the struct, as the header by default already includes this workaround of using the |
Okay, yes my bad. The issue is clear to me right now. I think it is a reasonable thing that it generates a |
(there was going to be a lengthy comment here about how there is still weirdness in @intToEnum, but it turns out I just cast to the wrong type and wasn't able to read the difference). I think this is solved as of my current zig-git version ( |
I'm trying to import/cInclude a header file that defines an enum type, and a struct with an enum member:
when assigning the values I get a type mismatch:
Shouldn't this be working? I also tried wrapping the enum in a
typedef enum ImGuiConfigFlags_ {...} ImGuiConfigFlags
and then using it asImGuiConfigFlags
(no underscore orenum
) in the struct but the same problem occurs.The text was updated successfully, but these errors were encountered: