interopmultiple-languageslanguage-interoperability

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?


Solution

  • 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):