Calling C
- @cImport. @cImport translates C headers into Zig at build time: bindings without a generator step.
- C types in Zig. C types map explicitly: c_int, sentinel strings, extern structs matching layouts.
- Linking. The build links C libraries directly: Zig as the glue over any native stack.
Exporting Zig
- export. export gives a function the C ABI: Zig callable from anything that speaks C.
- ABI-stable surfaces. Exported APIs stay C-shaped: plain structs, no error unions across the border.
- Errors at the border. Boundary functions translate errors to codes: the union stays home, the contract crosses.
Replacing or Extending C Components
- Incremental replacement. Zig replaces C file by file: same build, same ABI, safety rising per commit.
- Drop-in libraries. A Zig library exporting the old header is a drop-in: consumers never noticing the swap.
- Honest costs. Interop is powerful, not free: translated headers audited, layouts verified by test.
Before and after this level
- Before: Level 7: Modules & Build System: Modules, Zig Build, Dependencies and Cross Compilation.
- Next: Level 9: Testing & Debugging: Built-In Testing, Debugging Native Programs, Safety Modes.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Zig Level 8: C Interoperability cover?
Calling C, Exporting Zig, Replacing or Extending C Components: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 7: Modules & Build System, which covers Modules, Zig Build, Dependencies and Cross Compilation.