News for hackers. Stuff that matters.
Re:How I Wrote a Modern C++ Library in Rust by simias on Monday December 03, 2018 @11:01AM (#18589720)
That could actually somewhat work for C++ and Rust (although getting things like generics/templates across would be a huge challenge and you'd lose Rust's safety guarantees at the unsafe C++ interface. Also good luck dealing with exceptions). For Go and D you have a bigger problem: garbage collection. Having two different runtimes play well with each other is far from trivial and could hurt performance.

The main reason the C ABI is de-facto the lingua franca for language bindings is because it's almost runtime-less. You basically only need to agree on things like stack layout and where the parameters/return values go. It's a super low bar.

Dealing with C++ objects, overloaded functions, namespacing, exceptions etc... Now that's a whole different can of worms. How would you automagically map something like std::cout and its operator<< in Rust or Go for instance?

Re:How I Wrote a Modern C++ Library in Rust by shaklee3 on Tuesday December 04, 2018 @11:16AM (#18600738)
This has somewhat been solved by cgo by having it documented clearly, and turning a runtime flag on that tells you whether you're doing something you're not supposed to.
Re:How I Wrote a Modern C++ Library in Rust by masklinn on Monday December 03, 2018 @01:32PM (#18591472)
> Dealing with C++ objects, overloaded functions, namespacing, exceptions etc... Now that's a whole different can of worms. How would you automagically map something like std::cout and its operator<< in Rust or Go for instance?

You'd define std::cout and operator<< in terms of a sane underlying reader/writer ABI?

Re:How I Wrote a Modern C++ Library in Rust by simias on Tuesday December 04, 2018 @06:02AM (#18598279)
Right, but my point is that then you're generating a complex FFI (which requires high level info about how "operator<<" on std::cout implements streaming and not bitshifting as usual), not a simple binding. Doing that automatically and "standardly" would be quite complex. Those aren't primitive types, they're abstraction built on top of the language's typesystem, g++ is not aware of what a "stream" is in C++, nor is rustc aware of what the Read and Write traits mean.