Quote from Identifiers
Identifiers [...] must not overlap with any keywords. [...]
If a name that does not fit these requirements is needed, [...] the @"" syntax may be used.
// example.zig
// run with `zig run example.zig -lc`
const c = @cImport({
@cInclude("error.h");
});
pub fn main() !void {
// Names inside `@"` `"` are always recognised as identifiers.
_ = c.@"error"(0, 0, "this uses @\"error\"\n");
}
You can also assign c.@"error"
to a new function c_error
or use @cDefine("_error", "error");
like you did:
// alternatives.zig
// run with `zig run alternatives.zig -lc`
const c = @cImport({
@cInclude("error.h");
@cDefine("_error", "error");
});
const c_error = c.@"error";
pub fn main() !void {
_ = c._error(0, 0, "this uses _error\n");
_ = c_error(0, 0, "this uses c_error()\n");
}