Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

interop - How do multiple languages interact in one project?

I heard some people program in multiple languages in one project. I can't imagine how the languages interact with each other.

I mean there is no Java method like

myProgram.callCfunction(parameters);

never happens or am I wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Having multiple languages in one project is actually quite common, however the principles behind are not always simple.

In the simple case, different languages are compiled to the same code. For example, C and C++ code typically is compiled into machine assembler or C# and VB.Net is compiled into IL (the language understood by the .NET runtime).

It gets more difficult if the languages/compilers use a differnt type system. There can be many different ways, basic data types such as integer, float and doubles are represented internally, and there is even more ways to represent strings. When passing types around between the different languages it must be sure that both sides interpret the type the same or - if not - the types are correctly mapped. This sort of type mapping is also known as marshalling.

Classic examples of interoperability between different program languages are (mostly from the Windows world):

  • The various languages available for the .NET platfrom. This includes C#, VB.Net, J#, IronRuby, F#, XSLT and many other less popular languages.
  • Native COM components written in C++ or VB can be used with a huge variety of languages: VBScript, VB, all .NET languages, Java
  • Win32 api functions can be called from .NET or VB
  • IPC (inter process communication)
  • Corba, probably the most comprehensive (and most complex) approach
  • Web services and other service-oriented architectures, probably the most modern approach

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...