4 ms·
I wonder what the plan is for getting swift interop with C++, given that all the Be/Haiku APIs are C++ (IIRC) and swift has no ability to call into C++ code dir
by quux 9y ago
I wonder what the plan is for getting swift interop with C++, given that all the Be/Haiku APIs are C++ (IIRC) and swift has no ability to call into C++ code directly.
- mhh__ 9y agoIf you want to see one way of doing this, have a look at how D does it: The function mangling and v-table (for single inheritance) are matched between the two languages.
- Someone 9y agoNitpick: C++, the language, has function name mangling nor v-tables. Both are implementation-specific (and need not even be identical on a single platform. Early C++ compilers on Windows were incompatible with each other, for example)
- dzonga 9y agoyou can call c/c++/obj-c functions from swift
- sswezey 9y agoYou can call C and Obj-C. You can't call C++ code directly, it would have to go through a C/Obj-C shim first.
- FreeFull 9y agoHaiku is POSIX compatible, so at the very least there are the standard C APIs. It is true you need to call into C++ for things like GUIs though (unless you use a port of a C GUI library).
- oscargrouch 9y agoFor now i think you can just wrap it all up in C headers, and implement them in C++, calling the right API. But giving the way the Swift compiler is itself written in C++ and tied to the LLVM, i bet it will be "easy" for the Swift compiler team to create interoperability between C++ and Swift. I think their current goal with ABI compability is one step in that direction.. so it will be just a question of Swift understanding C++ mangling in elf/coff/mach-o objects for the link time, and interpret C++ headers using Clang for the compile time. Given all that, is not hard to predict that Swift will probably have the best interop with C++ code than any other language out there.
- quux 9y agoThe swift compiler being written in C++ has nothing to do with how swift calls into C++ code.
- oscargrouch 9y agoTheres a first part of my comment where i talk about ABI, name mangling, etc.. a goal Swift 4 is achieving, and i bet the possibility to reference C++ linked symbols will be there eventually, giving the project is very tied to LLVM and Clang. Then there's a second part where i comment about the ability to parse C++ header using Clang when parsing Swift code, so you can get this in compile time. (You probably noted this part and lost some of the information that i've implied from the first). So, i didnt imply that it was because the Swift compiler was written in C++ that it would have these properties, but because of its history of being tied together with LLVM and Clang, being coded by the same people behind LLVM and Clang. I hope it gets more clear what i've meant to imply with my comment now.