3 ms·
> What won my heart is just how simple it is to import C code into Swift to bring the type definitions from a header file, and call into the C code transparentl
by rvz 7y ago
> What won my heart is just how simple it is to import C code into Swift to bring the type definitions from a header file, and call into the C code transparently from Swift. This really is a gift of the gods to humankind.
If you like creating wrappers around C libraries, perhaps this is the most overlooked feature in Swift, called the 'ClangImporter'. Compared with Rust's bindgen, bindgen looks like a more complicated bindings generator even at the C level with you tweaking the options and other knobs to 'get it right' for your specific wrapper project.
This is before you even start to write a higher-level and more idiomatic wrapper and ClangInporter binds the C part to generate Swift functions for you by default. Similarly, Zig also has this too which is "@cImport" with the path to the header file as the input IIRC.
It also looks like Swift is getting C++ interop for this too. [0]
[0] https://forums.swift.org/t/manifesto-interoperability-between-swift-and-c/33874 https://forums.swift.org/t/manifesto-interoperability-betwee...