17 lines
317 B
Plaintext
17 lines
317 B
Plaintext
// hare run -lc ffi.ha
|
|
|
|
use fmt;
|
|
use strings;
|
|
|
|
@symbol("strdup") fn cstrdup(_: *const char) *char;
|
|
@symbol("free") fn cfree(_: nullable *void) void;
|
|
|
|
export fn main() void = {
|
|
let s = strings::to_c("Hello, World!");
|
|
defer free(s);
|
|
|
|
let dup = cstrdup(s);
|
|
fmt::printfln("{}", strings::fromc(dup))!;
|
|
cfree(dup);
|
|
};
|