在一个项目中多种语言如何交互? [英] How do multiple languages interact in one project?

查看:917
本文介绍了在一个项目中多种语言如何交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说有人在一个项目中使用多种语言进行编程.我无法想象这些语言之间如何相互作用.

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

我的意思是没有像这样的Java方法

I mean there is no Java method like

myProgram.callCfunction(parameters);

从没发生过还是我错了?

never happens or am I wrong?

推荐答案

在一个项目中拥有多种语言实际上是很普遍的,但是背后的原理并不总是那么简单.

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

在简单的情况下,将不同的语言编译为相同的代码.例如,通常将C和C ++代码编译为机器汇编程序,或者将C#和VB.Net编译为IL(.NET运行时可以理解的语言).

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.

不同程序语言之间互操作性的经典示例是(大多数来自Windows世界):

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

  • .NET平台提供的各种语言.其中包括C#,VB.Net,J#,IronRuby,F#,XSLT和许多其他较不流行的语言.
  • 用C ++或VB编写的本机COM组件可以与多种语言一起使用:VBScript,VB,所有.NET语言,Java
  • 可以从.NET或VB调用Win32 api函数
  • IPC(进程间通信)
  • Corba ,可能是最全面(也是最复杂)的方法
  • Web服务和其他面向服务的体系结构,可能是最现代的方法
  • 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

这篇关于在一个项目中多种语言如何交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆