The following C header doesn't work with @cImport:
typedef enum {
f32,
u32,
} BadEnum;
Here's a zig file to demonstrate:
const c = @cImport({
@cInclude("badenum.h");
});
pub fn main() void {
var a : c.BadEnum = undefined;
}
$ zig build-exe badenum.zig -I.
zig-cache/o/HGGngBrkPyxavUDS-SZLX2-M6376Z_CrbZVjk7IMXz5X9huyNP6Zn7L4sGYyIly5/cimport.zig:1:5: error: declaration shadows primitive type 'f32'
pub const f32 = @enumToInt(enum_unnamed_1.f32);
^
zig-cache/o/HGGngBrkPyxavUDS-SZLX2-M6376Z_CrbZVjk7IMXz5X9huyNP6Zn7L4sGYyIly5/cimport.zig:2:5: error: declaration shadows primitive type 'u32'
pub const u32 = @enumToInt(enum_unnamed_1.u32);
^
./badenum.zig:5:13: note: referenced here
var a : c.BadEnum = undefined;
^
zig-cache/o/HGGngBrkPyxavUDS-SZLX2-M6376Z_CrbZVjk7IMXz5X9huyNP6Zn7L4sGYyIly5/cimport.zig:8:21: note: referenced here
pub const BadEnum = enum_unnamed_1;
^
./badenum.zig:5:14: note: referenced here
var a : c.BadEnum = undefined;
Modifying the enum identifiers to non zigkeywords fixes the issue. Zig's translate-c needs to be aware whether or not a C identifier is a keyword and handle it accordingly.
Issue raised on reddit: https://www.reddit.com/r/Zig/comments/ivv1j3/declaration_shadows_primitive_type_error/
The following C header doesn't work with
@cImport:Here's a zig file to demonstrate:
Modifying the enum identifiers to non zigkeywords fixes the issue. Zig's translate-c needs to be aware whether or not a C identifier is a keyword and handle it accordingly.
Issue raised on reddit: https://www.reddit.com/r/Zig/comments/ivv1j3/declaration_shadows_primitive_type_error/