-
-
Save schroffl/03b2eee4dfe347d8589574f3f919ce37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const c = @cImport({ | |
@cInclude("c-header.h"); | |
}); | |
const MyInputType = struct { | |
value: u8 | |
}; | |
const MyResultType = struct { | |
input: type, | |
pub fn doSomethingWithInputType(comptime self: MyResultType) void { | |
std.debug.warn("{}\n", @memberName(self.input, 0)); | |
} | |
}; | |
pub fn main() void { | |
const a = getResultType(MyInputType); | |
const b = getResultType(struct { another_input_type: u8 }); | |
a.doSomethingWithInputType(); | |
b.doSomethingWithInputType(); | |
} | |
fn getResultType(comptime input_type: type) MyResultType { | |
// As soon as I add the c call, I get 'unable to evaluate constant expression'. | |
// If you comment the line below this snippet should run properly. | |
c.some_function(); | |
return MyResultType { | |
.input = input_type | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment