3 ms·
In Zig you literally just import a C header and start coding. There's no FFI like rust and no header guards like C++.
by LAC-Tech 4y ago
In Zig you literally just import a C header and start coding. There's no FFI like rust and no header guards like C++.
- Tozen 4y agoBy the way, Vlang has that level of C interop as well (https://github.com/vlang/v/blob/master/doc/docs.md https://github.com/vlang/v/blob/master/doc/docs.md), plus an outright C2V transpiler (https://github.com/vlang/c2v https://github.com/vlang/c2v) and can be compiled to human-readable C.
- mort96 4y agoThe question wasn't if you can call C from Zig code, but if you can call Zig from C code.
- brabel 4y agoYou can, but you must explicitly declare your function wants to use C calling convention. See https://ziglang.org/documentation/master/#toc-export https://ziglang.org/documentation/master/#toc-export for an example, looks like this: fn internalName() callconv(.C) void {} It will not compile if you use types that the C-calling convention does not allow. Without this, no, you can't call Zig from C.
- LAC-Tech 4y agoMy mistake