Glossary Updates6 new terms added to the glossaries · October 11, 2026, 13:38 CEST
AI TechDocKnowledge

Glossary · 6 · SDK interoperation

Foreign function interface (FFI)

Also known as: FFI

In programming languages, a foreign function interface (FFI) is a mechanism by which code written in one programming language calls functions, and uses data types, of code written in another, most often native libraries with a C calling convention, which makes the call depend on the binary interface of the foreign code.

  • SDK interoperation
  • Language interoperability

In one sentence

A foreign function interface (FFI) lets code in one language call functions written in another, usually native C libraries, through their binary interface.

Example

A Python test tool loads a device vendor's C library with ctypes, declares the argument and return types of its read function and calls it to fetch a sensor value.

How it applies

  • Hardware SDKs: Device and accelerator kits usually ship a C or C++ library. FFIs are how higher-level languages reach it: Python's ctypes, a foreign function library that loads shared libraries and calls their functions; Java's Java Native Interface (JNI); Rust's extern blocks, which declare foreign function signatures to be called in unsafe code.
  • ABI dependence: An FFI call crosses a binary boundary. Caller and callee must agree on the application binary interface (ABI): calling convention, data layout, sizes of types and who frees memory. A mismatch is not caught by a compiler and can corrupt memory or crash the process.
  • Mobile platforms: On Android, JNI connects Java or Kotlin code with native code built by the NDK.
  • Developer SDKs: Multi-language SDKs often implement one core in C, C++ or Rust and expose it through FFIs to other languages, so that behavior stays the same across languages and fixes are made once.
  • Documentation: Document the C-level API exactly (types, ownership, threading, error codes), the supported platforms and ABIs and which language wrappers exist. Wrappers built on an FFI inherit every constraint of the native layer.

FFI vs. language binding

An FFI is the mechanism a language offers for calling foreign code. A language binding is the library built on it that makes a particular foreign library usable in an idiomatic way, with native types, error handling and documentation. Bindings are written by hand on an FFI or generated by tools.

External references