- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
translate-cC to Zig source translation feature (@cImport)C to Zig source translation feature (@cImport)
Milestone
Description
macro.h:
#define noargs someargs(Flag1)
typedef enum {
Flag0,
Flag1
} Flags;
int someargs(Flags flags);
macro.c:
typedef enum {
Flag0,
Flag1
} Flags;
int someargs(Flags flags) {
if (flags == Flag1) {
return 1;
} else {
return 0;
}
}
test.zig:
const c = @cImport({
@cInclude("macro.h");
});
pub fn main() !void {
_ = c.noargs;
}
Then compile with zig build-exe test.zig --c-source macro.c -lc -I.
and the error
zig-cache/o/INfBWWWMN1znJ7cpk1aHFpWrWqAEwqd-Uefh0pPlK7Sau8WYxYrtuxOF09n_V9xa/cimport.zig:225:35: error: expected type '.cimport:2:11.enum_unnamed_1', found 'c_int'
is produced.
As far as I can tell this is only a problem on the right hand side of c macros, in other places @intToEnum
is inserted to make it work. I don't know why expressions in macros are handled differently but it's probably causing other bugs too.
Metadata
Metadata
Assignees
Labels
translate-cC to Zig source translation feature (@cImport)C to Zig source translation feature (@cImport)
Type
Projects
Relationships
Development
Select code repository
Activity
Vexu commentedon Jun 27, 2020
Macros are translated separately from the rest of the code and have no type info available which is why the cast is not being inserted. Fixing this would require finding the types of the function and the argument (possibly through multiple macros) and casting based on that.
extern enum
#9164