Error codes

E0040: an extern declaration doesn't fit its C prototype

In a terminal: auk explain E0040 prints this page.

On this page

The string of an extern fn is the C function's prototype, and each Auk parameter and the result must fit the C type in the same position: C integers are int, bool is bool, float/double are float, const char * is str (a result may be str?: NULL is none), other pointers are ffi.Ptr or an extern type, a list [T] is T *, a var parameter is an out-parameter (int *, char **), and void is (). A "T (*)(params)" prototype calls a function pointer, which comes first as an ffi.Ptr, and "(T)" casts its one argument, an ffi.Ptr or an extern type, to the pointer type T; "#embed path" is a file read at compile time, returned as [int], str, ffi.Ptr or int (its length), with no parameters. Variadic functions, structs by value and callbacks from C into Auk aren't supported.

Wrong#

toml
[package]
name = "app"
version = "0.1.0"
effects = ["ffi"]
auk
extern fn strlen(s: str): str = "size_t strlen(const char *)"

fn main() uses ffi { print(strlen("hello")) }

Fixed#

auk
extern fn strlen(s: str): int = "size_t strlen(const char *)"

fn main() uses ffi { print(strlen("hello")) }

Common causes#

  • An Auk type that can't hold the C value (a size_t declared str).
  • A C typedef the FFI doesn't know: write its underlying type, or extern type X = "X".
  • A prototype with a different number of parameters than the Auk declaration.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page