r/Compilers • u/yuehuang • Sep 07 '26
C++ Interop, a good or bad idea?
I reached the point in my compiler that I can add C++ Interop, the AI has a long detailed plan. LLVM+ClangAST will do the parsing to types that is mapped to my language syntax.
Reason for C++ support is open existing library support written for C++, not all of them have C API. A search for existing languages rejected or abandoned C++ Interop the high cost to maintain and the language stability.
Anyone else have experience?
0
Upvotes
21
u/KAMEHAMEHAMEHAAAA Sep 07 '26
For the love of god stop delegating your brain and learning process to generative AI.
6
u/ZachVorhies Sep 07 '26
if you keep it as a C interface, it will bind with literally every single language in existence
C is the lingua franca of source code inter operability. Unless you really really need the C++ interface, I would try to keep the C interface as much as possible, and even have a C++ interface on the other side that binds to that and does it the C++ way on the other side of the interface boundary.
For more information look up C FFI.
if you keep it the way that it is, you can use python and you can use rust, the latter which is even more important
4
u/kindredseer Sep 08 '26 edited Sep 08 '26
Yes, C++ interop is far more complicated than any other language. The header libraries are immense and difficult to parse all the template variations, not to mention the mangling scheme.
As well as that, MacOS uses Clang’s libc++, Linux uses GCC’s libstdc++ and Windows doesn’t come with one installed, but you can include one of the other two unless you want to interop with msvcp140.dll or something.
That said, I have been tackling it with my madc language. I have a lot of it working but it’s been a nightmare, and I’m not sure I recommend it. It has caused considerable bloat and complexity. I didn’t abandon it, but I have a bit of the buyers remorse.
1
u/Rich-Engineer2670 Sep 07 '26
Do you mean C++ or C interop? There is a difference. If it's C interup, do it -- there are too many libraries out there you'll miss out on -- if you can add C++ in, great. Or, crazy idea, add a backend to transpile ot C++. I always wanted the option of C++ transpiling which gave me the bets of both worlds. After all, C and C++ have been beaten to squeeze every bit of performance out of them we can get.