Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What language has C++ interop?


Haskell:

It is implemented as a library, without needing compiler support [*].

You can write C++ in TemplateHaskell (Haskell's strongly typed AST-generating macro system), which allows you to use Haskell variables in scope inside your C++ functions.

The "inline-c" library allows this for C and C++.

Example of its use in the Haskell OpenCV bindings: https://hackage.haskell.org/package/opencv-0.0.2.1/docs/src/...

The way it works: It invokes the C++ compiler for you to generate a wrapper function that closes over the Haskell variables used in your code snippet, and on the Haskell side generates a corresponding type-safe function call for you.

This approach allows you to use all C++ features that a C++ compiler supports. But it also carries the drawback of ... invoking a C++ compiler, which gives you the slow build speed of C++.

[*] Some compiler support was added to be able to specify compiler flags that are specific to the C++ compiler but not the C compiler.


Love the non-standard formatting :). It took me a while to see where haskell ended and C++ started. Seems very powerful.


D does. Not source compatible, but mangling and ABI for linking. And D can generate headers for `extern(C++)` declarations defined in D


Swift just added C++ interop in version 5.9. https://forums.swift.org/t/c-interoperability-in-swift-5-9/6...


Nim does as well. You can use the C++ backend and wrap a decent bit of C++. The imports aren’t automatic so you need to define the FFI, but you can call templates, implement virtual methods, call constructors, etc.

NimForUE takes advantage of this: https://youtu.be/Cdr4-cOsAWA


i've come across carbon (google's c++-next language), clasp (common lisp with an llvm backend), felix (compiler generates c++), and maybe a couple of others i'm forgetting.

also some languages have packages that deal with c++ interop to varying extents - see this discussion: https://www.reddit.com/r/ProgrammingLanguages/comments/huhy8...


Besides all other answers, .NET ecosystem, and IBM i TIMI, by having a C++ compiler as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: