Skip to main content

C Interoperability Overview

Zynx is designed to interoperate directly with C code and C ABIs. This section describes the core tools, how data is represented at the boundary, and how C interop fits alongside the package system.

Core Interop Tools

Zynx supports C interoperability through three primary mechanisms:

  • extern functions – declare and call C APIs directly from Zynx.
  • bindgen – generate Zynx declarations from existing C headers.
  • ffi modules – compile local C sources/headers and generate bindings as part of the project.

Together, these tools cover most integration scenarios without introducing an additional language boundary inside regular Zynx code.

Data Representation

For ABI-compatible C data declarations, Zynx provides explicit C representation attributes:

  • @native struct
  • @native enum
  • @native union
  • @bits(N) inside @native struct

These attributes are for layout and ABI compatibility at the C boundary. They are not intended for normal high-level Zynx semantics and should be used primarily when matching an external C definition.

Package and Interop Boundary

C interoperability and package management are related but distinct concerns.

  • Use package for Zynx libraries resolved from registries or git.
  • Use ffi for local C code that must be compiled and bound into the project.

Registry or git packages may be installed from source or from registry-provided binary bundles, but they do not replace ffi modules for local C compilation and binding generation.

For a detailed walkthrough of configuring and using ffi modules in practice, see: