From 6b2545224752be74de35166c3dcda9ff5bdb79e3 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sat, 17 Jan 2026 16:33:36 +0000 Subject: Add C++ interop support. --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'README.md') 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 +include + +raw { + std::vector 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 -- cgit v1.2.3