4 ms·
One of the first things I'm looking at in Go and Rust is compatibility with C. I haven't used D, but this page makes it look as good or better from that perspe
by SloopJon 11y ago
One of the first things I'm looking at in Go and Rust is compatibility with C. I haven't used D, but this page makes it look as good or better from that perspective:
http://dlang.org/interfaceToC.html http://dlang.org/interfaceToC.html
Can anyone comment further?
- rlonstein 11y agoI can. I've written D interfaces to vendor-supplied C and C++ SDKs and for an open source C library (libusb). We're using this at work. For C, it's relatively easy and mechanical to translate by hand but https://github.com/jacob-carlborg/dstep https://github.com/jacob-carlborg/dstep makes starting trivial. For C++, I had two cases- one was easy as that vendor provided a C handle and function call syntax while the other required doing a C shim (facade) to wrap up the object. I didn't find SWIG to be useful but did examine its output to get ideas. The built-in unit testing in D is very handy.
- dbaupp 11y agoIt seems Rust and D have very very similar C FFIs, see http://doc.rust-lang.org/book/ffi.html http://doc.rust-lang.org/book/ffi.html . https://github.com/crabtw/rust-bindgen https://github.com/crabtw/rust-bindgen is a tool in the vein of dstep. (Rust has the advantage of having no runtime beyond what C needs unlike D with its current garbage collector, so FFI, especially exposing a C interface, is likely somewhat simpler.)