开发者

How much interoperability is there between C++ and Scala?

Everybody knows about Java and Scala, but how much interoperability is there between C++ and Scala. Can classes 开发者_C百科from one be be used by the other, for example?


It's not that simple at all. Java and Scala work on the same virtual machine and scala has been designed to work well with java.

C++ generates native code, and even each compiler has its own way to generate that native code. That means that some class compiled with Visual Studio won't interact easily with another class compiled with gcc.

If you need to interact with C++, you need to use some glue with JNI http://en.wikipedia.org/wiki/Java_Native_Interface. I believe it should be straightfoward to use it with scala. You can make interaction somewhat more comfortable using Swig http://www.swig.org/


To make this kind of interoperability even possible, both implementations must compile for the same intermediate language (i.e. Java bytecode, .Net IL, LLVM). Scala.Net and C++/CLI is the closest combination — both produce code for .Net. But even then it's not that simple, as a class in Scala and a class in C++ stand for slightly different things.

Typically, Scala stands for Scala for Java VM, and C++ stands for C++ for native code, so general answer should be “not much more than between any other two randomly picked languages”.


I would've checked out JNAerator. It builds bridges from C/C++/Obj-C header files to Java interfaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜