summaryrefslogtreecommitdiff
path: root/zig-c-interop
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-09-14 22:28:47 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-09-14 22:28:47 +0200
commit8437bd12a54c6fe62c92b9a27fef03a5ec2a35cf (patch)
tree0934a84cbe4a9464ff762bf239845a9eb1260f29 /zig-c-interop
parent134f855b537b714eb98bc1e6e1e4790b4d6491a3 (diff)
downloadprobe-8437bd12a54c6fe62c92b9a27fef03a5ec2a35cf.tar.gz
Added basic Zig and C interoperability example
Diffstat (limited to 'zig-c-interop')
-rw-r--r--zig-c-interop/Makefile2
-rw-r--r--zig-c-interop/billy.c3
-rw-r--r--zig-c-interop/billy.h1
-rw-r--r--zig-c-interop/main.zig9
4 files changed, 15 insertions, 0 deletions
diff --git a/zig-c-interop/Makefile b/zig-c-interop/Makefile
new file mode 100644
index 0000000..b0e2753
--- /dev/null
+++ b/zig-c-interop/Makefile
@@ -0,0 +1,2 @@
+default:
+ zig run -I. main.zig
diff --git a/zig-c-interop/billy.c b/zig-c-interop/billy.c
new file mode 100644
index 0000000..9544156
--- /dev/null
+++ b/zig-c-interop/billy.c
@@ -0,0 +1,3 @@
+#include "billy.h"
+
+int sum(int a, int b) { return a + b; };
diff --git a/zig-c-interop/billy.h b/zig-c-interop/billy.h
new file mode 100644
index 0000000..6142d6c
--- /dev/null
+++ b/zig-c-interop/billy.h
@@ -0,0 +1 @@
+int sum(int a, int b);
diff --git a/zig-c-interop/main.zig b/zig-c-interop/main.zig
new file mode 100644
index 0000000..8d16cd1
--- /dev/null
+++ b/zig-c-interop/main.zig
@@ -0,0 +1,9 @@
+const print = @import("std").debug.print;
+
+const billy = @cImport({
+ @cInclude("billy.c");
+});
+
+pub fn main() void {
+ print("Billy says 2+4={d}\n", .{billy.sum(2, 4)});
+}