-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fixed extern enums having the wrong size #970
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
Conversation
Imo explicit extern enum tag types should be disallowed and extern enum should mean that the tag type is 'c_int'. (GCC, Clang and MSVC all seem to use 'int' or 'unsigned int') |
#MissClick |
|
I had a discussion about this in a different context a while ago and the conclusion was that it's most likely a theoretical concern. There appear to be no production compilers that would willingly pick a size < It's kind of pointless because most ABIs dictate promotion to word size anyway when passing it around in registers or embedding it in a struct. gcc and clang have |
I'll have a look at this PR tonight. As for the windows threading issue, I may have found a clue:
|
Since both @bnoordhuis and @alexnask have given good reasons for just using |
There's one detail I want to double check - The Clang API has the concept of specifying int type of enums. I believe right now in translate-c we support this. So that makes me think there is some GNU attribute that lets you do this, although I can not find it. See also https://stackoverflow.com/questions/9524342/how-to-specify-enum-size-in-gcc#9525276
Only if the target C environment would let you do so. Zig gives the promise of "C ABI compatibility" in various contexts, one of which being So for I'll look more into this tonight |
#It'sNeverThatSimple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so this is definitely an improvement. Feel free to merge.
I'll make an issue to track C ABI compatibility for enums and we can revisit making it a compile error at that time. Until then we can leave the ability to override the int type even for extern enums, as an available workaround for zig potentially not supporting e.g. enums upgrading to c_longlong if you use such a value in it and are targeting GNU.
I agree with this in spirit, but if they were going to specify the tag type themselves, they would still have to use |
For
extern enum
s,get_smallest_unsigned_int_type
does not give us the tag type that GCC or Clang uses for enums. I've chosen to usec_int
as a tag type forextern enum
as it seems to be more in line with what they do, but I'm not sure if that is correct either.C Spec:
It seems that C compilers are allowed to use the smallest size, so how do we handle that when mixing Zig with some niche C compiler that does this?
Also, should specifying the tag type on
extern enum
s be a compiler error?