Skip to content

Allow enums with C compatible tag types in extern structs/functions #1467

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

Closed
Hejsil opened this issue Sep 4, 2018 · 0 comments · Fixed by #6427
Closed

Allow enums with C compatible tag types in extern structs/functions #1467

Hejsil opened this issue Sep 4, 2018 · 0 comments · Fixed by #6427
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Hejsil
Copy link
Contributor

Hejsil commented Sep 4, 2018

As seen in #977, the tag types of enums in the C spec is unreliable. @isaachier even points out that many C projects avoid the C enum so they can ensure that their lib is "ABI-able".

But Zig has explicit tag types for enums, so when fixing up code translated with translate-c, we should be able to replace code such as this:

typedef E uint32_t;
enum { A, B, C };

struct S {
    E e;
};

With:

pub const E = enum(u32) { A, B, C };
pub const S =  extern struct {
    e: E,
};

Sadly, this is not allowed:

test.zig:3:5: error: extern structs cannot contain fields of type 'E'
    e: E,
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 4, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018
@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. accepted This proposal is planned. labels Apr 12, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Apr 12, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 3, 2020
tadeokondrak added a commit to tadeokondrak/zig that referenced this issue Sep 26, 2020
tadeokondrak added a commit to tadeokondrak/zig that referenced this issue Sep 30, 2020
tadeokondrak added a commit to tadeokondrak/zig that referenced this issue Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants