Hacker News new | ask | show | jobs
by jbritton 2220 days ago
One thing I like about C as a systems programming language is that it is easy for every other language to bind to it. I’m fine with C++ if the external interface is extern “C”, but that is often not the case. I don’t know how easy it is for other languages to bind to Rust. It would be nice if a language could automatically generate Swig definition files or something similar. However one is going to run into language semantics and impedance mismatches with richer languages. The simplicity of “C” makes a nice bind target. Although I have yet to see a thorough binding to Win32, so I suspect the preprocessor makes this difficult.
1 comments

Check out TerraFX[1], created and maintained by Tanner Gooding, owner of System.Numerics in .NET Core. He uses another project he maintains called ClangSharp[2] to scan Windows SDK header files and generate blittable, marshalling-free C# bindings. There are many things in C header files that are not easily bound, such as macros; we do a lot of manual or partially-automated work to account for those.

TerraFX is greater than just Windows bindings[3] but it is certainly useful for even just that. I've contributed a lot of bindings recently for some low-level Windows headers. Contributions are welcome!

[1] https://github.com/terrafx/terrafx

[2] https://github.com/microsoft/clangsharp

[3] https://github.com/terrafx/terrafx.interop.windows