summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-17 16:33:36 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-17 16:33:36 +0000
commit6b2545224752be74de35166c3dcda9ff5bdb79e3 (patch)
treeaa2765253769a0a1635d9ffc22738ec6598254c1 /README.md
parentb885629239d04d2860a8853799a3d335d8bec154 (diff)
Add C++ interop support.
Diffstat (limited to 'README.md')
-rw-r--r--README.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/README.md b/README.md
index 2424fba..9a5c008 100644
--- a/README.md
+++ b/README.md
@@ -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