It's a bit ugly due to cbindgen not supporting const-generic expressions and macro-expansion being nightly-only. It seems like this will be a generally useful mechanism to be able to use values which are not traditionally FFI-safe across FFI boundaries.
[0]: https://github.com/RediSearch/RediSearch/blob/cfd364fa2a47eb...
Aren't there ABI cases where e.g.
struct foo { float X, Y; }
would be passed in e.g. fp registers whereas struct { char[8]; }
would not?I sort of mentioned this in the blog but this is good clarification.
> if you want to pass a shared_ptr to Zig, you need to pass a pointer to the shared pointer
For lore, I believe this GitHub thread is where I first learned about the how types of the same size/alignment can still have different ABIs :) https://github.com/microsoft/win32metadata/issues/623#issuec...
Direct C++ interop is doable, by embedding Clang into Zig and using its AST, but this is significantly more work and it needs to be done in the Zig compiler. As a Zig user, going through C is about as good as you can do, probably.
fn stackExample() void {
var some_cpp_type: c.SomeCppType = undefined;
c.some_cpp_type_ctor(&some_cpp_type);
defer c.some_cpp_type_dtor(&some_cpp_type);
// ...
}
swiftcoder•2mo ago
kccqzy•2mo ago
swiftcoder•2mo ago
It was an unholy welding of the two languages that mostly let Objective-C apps adopt some libraries from the broader C++ ecosystem. Plus the occasional cross-platform C++ codebase used it as a thin shim to provide a Cocoa-based UI...
pjmlp•2mo ago
nly•2mo ago
Rename a file to .mm and start using Objective C APIs. Very good interop