Skip to content
FutureBlitz

    Install

    Learn

    C interop

    Call C functions directly, share memory and structs with C, and turn a library's headers into a module.

    FutureBlitz calls C directly. An Extern block declares a library’s functions in C’s types, and the program calls them with no glue code and no wrapper to compile. These tutorials cover the types and strings C uses, pointers and the Unsafe code they need, structs, callbacks, how a package names its C libraries, and fb bindgen, which writes the declarations from a header. Most programs never need any of this: std already wraps the C libraries it uses.

    Tutorials

    1. Calling C Declare C functions in an Extern block and call them like your own, with C's types and out-parameters.
    2. Strings and buffers Pass text to C as CStrings, keep a C string alive with CString.From, and share memory with C through a Buffer.
    3. Pointers and Unsafe Allocate C memory, read and write through Ptrs, and keep that code inside Unsafe blocks.
    4. Structs with @CLayout Lay a Struct out as C does, pass it to C by value and by pointer, and measure it.
    5. Callbacks Hand C a function or a lambda to call back, as qsort's comparison, and call a C function pointer yourself.
    6. Native libraries in project.toml Name a package's C libraries in [native], static, system, or dynamic, and point Extern blocks at them with Lib.
    7. bindgen Turn a C header into a FutureBlitz module with fb bindgen, and use the library through it.

    The rules behind this area are in the language reference.

    Report an issue with this page or with FutureBlitz on GitHub.