diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 16:33:36 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 16:33:36 +0000 |
| commit | 6b2545224752be74de35166c3dcda9ff5bdb79e3 (patch) | |
| tree | aa2765253769a0a1635d9ffc22738ec6598254c1 /README.md | |
| parent | b885629239d04d2860a8853799a3d335d8bec154 (diff) | |
Add C++ interop support.
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -559,6 +559,41 @@ zc run app.zc --cc zig make zig ``` +### C++ Interop + +Zen C can generate C++-compatible code with the `--cpp` flag, allowing seamless integration with C++ libraries. + +```bash +# Direct compilation with g++ +zc app.zc --cpp + +# Or transpile for manual build +zc transpile app.zc --cpp +g++ out.c my_cpp_lib.o -o app +``` + +#### Using C++ in Zen C + +Include C++ headers and use raw blocks for C++ code: + +```zc +include <vector> +include <iostream> + +raw { + std::vector<int> make_vec(int a, int b) { + return {a, b}; + } +} + +fn main() { + var v = make_vec(1, 2); + raw { std::cout << "Size: " << v.size() << std::endl; } +} +``` + +> **Note:** The `--cpp` flag switches the backend to `g++` and emits C++-compatible code (uses `auto` instead of `__auto_type`, function overloads instead of `_Generic`, and explicit casts for `void*`). + --- ## Contributing |
