Skip to content

c translation of enum with multiple names matched to same value #1359

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
andrewrk opened this issue Aug 9, 2018 · 6 comments
Closed

c translation of enum with multiple names matched to same value #1359

andrewrk opened this issue Aug 9, 2018 · 6 comments
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Aug 9, 2018

This C code:

enum Foo {
    A = 1,
    B = 1,
};

Generates this Zig code:

pub const enum_Foo = extern enum {
    A = 1,
    B = 1,
};

Which is a compile error in Zig. It also generates:

pub const A = enum_Foo.A;
pub const B = enum_Foo.B;

Which are the actual symbols in the C namespace. So Zig will be OK omitting the second name with the same value as a previous item, but instead of the global names being the enum type, they have to be the integer type.

@andrewrk andrewrk added this to the 0.4.0 milestone Aug 9, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Sep 24, 2018
zacharycarter pushed a commit to zacharycarter/zeal_zig that referenced this issue Dec 15, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Mar 14, 2019
@andrewrk andrewrk added the translate-c C to Zig source translation feature (@cImport) label Jun 16, 2019
@distractedlambda
Copy link

distractedlambda commented Jul 7, 2019

Are there any workarounds in 0.4 right now? Otherwise I think this currently blocks me from using Vulkan without manually defining the external symbols.

@andrewrk
Copy link
Member Author

andrewrk commented Jul 8, 2019

Related proposal: #2115

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 21, 2019
@terrybrash
Copy link

This is blocking me from using SFML 2.5.

TBrashaw@TBRASHAW MINGW64 ~/Personal/hellozig (master)
$zig build run
C:\Users\tbrashaw\Personal\hellozig\zig-cache\o\ILACwgWFOG1pHE-3jW_kHoMsvMUYEBk4Gpt-WTmwzo_o_slYBH15ELQpcZnIYgLo\cimport.zig:325:17: error: enum tag value 56 already taken
    sfKeyDash = 56,
                ^
C:\Users\tbrashaw\Personal\hellozig\zig-cache\o\ILACwgWFOG1pHE-3jW_kHoMsvMUYEBk4Gpt-WTmwzo_o_slYBH15ELQpcZnIYgLo\cimport.zig:279:19: note: other occurrence here
    sfKeyHyphen = 56,
                  ^
(many more similar errors redacted)

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Oct 23, 2019
@jpittis
Copy link

jpittis commented Nov 30, 2019

This is blocking me using glib.h

error: enum tag value 32768 already taken
G_REGEX_MATCH_PARTIAL_SOFT = 32768,
note: other occurrence here
G_REGEX_MATCH_PARTIAL = 32768,

@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Jan 2, 2020
@Vexu
Copy link
Member

Vexu commented Jan 2, 2020

Extern enums now allow multiple names matched to same value.

@andrewrk andrewrk closed this as completed Jan 2, 2020
@jpittis
Copy link

jpittis commented Jan 7, 2020

This is huuuge! Thanks so much! <3

@andrewrk andrewrk modified the milestones: 0.7.0, 0.6.0 Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

5 participants