docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

#E0084: invalid foreign-function use

A C function, extern declaration or extern "C" fn breaks an FFI rule: a type C cannot hold (one the collector may move, a tuple, a Unicode char, a plain enum, a str result), a closure passed as a C callback, two declarations with different signatures, or a variadic argument C cannot take. The type is checked as resolved, through aliases and fields, and the help says what to write instead. Pass C-compatible types, and named functions as callbacks.

nabi
extern "C" {
    fn abs(x: i32) -> i32;
    fn abs(x: i64) -> i64;
}
error[E0084]: extern function `abs` is declared twice with different signatures: `fn(i64) -> i64` here, `fn(i32) -> i32` elsewhere
  --> main.nabi:3:5
   |
 2 |     fn abs(x: i32) -> i32;
   |     -- declared as `fn(i32) -> i32` here
 3 |     fn abs(x: i64) -> i64;
   |     ^^
   |
   = help: a C symbol has one signature: declare `abs` as `fn(i32) -> i32` here too, or drop this declaration

Declare each C function once, with its C signature:

nabi
extern "C" {
    fn abs(x: c_int) -> c_int;
    fn labs(x: c_long) -> c_long;
}
println(f"{unsafe { labs(-5) }}");
5

Related: E0025 unsupported ABI, E0061 operation needs unsafe

Found a mistake? Edit this page on GitHub. Last updated