当从C语言调用Go程序时,Go程序会被编译还是解释?

huangapple go评论79阅读模式
英文:

When a go program is called from C, is it compiled or interpreted?

问题

在C程序中调用Go函数时,Go是通过编译还是解释执行的呢?

英文:

I made a C program. And I made a go file with go functions defined.
In the C program, I called go functions. Is go called from C compiled or interpretted?

答案1

得分: 3

它总是被编译的。C语言不会在没有编译的情况下运行函数。

英文:

it is always compiled. C will never run function without compilation.

答案2

得分: 3

你制作了一个C程序,并且创建了一个包含Go函数定义的go文件。在C程序中,你调用了Go函数。

你创建了一个调用C函数的Go程序(反过来目前还不可能)。然后你显然又从C中调用了Go函数,这有点奇怪,并且大部分情况下没有太多意义。请参考https://stackoverflow.com/a/6147097/532430。

我假设你使用gccgo来编译你的程序。因为如果你使用Go的gc编译器,那么关于你的程序是用哪种语言编写的就不会有任何混淆。

Go是编译型语言。gccgo是GCC的Go前端,而GCC代表GNU编译器集合。

英文:

> I made a C program. And I made a go file with go functions defined. In the C program, I called go functions

You made a Go program which calls C functions (the other way around is not yet possible.) Then you're apparently calling Go functions from C again which is a bit weird and doesn't make much sense most of the time. See https://stackoverflow.com/a/6147097/532430.

I'm going to assume you used gccgo to compile your program. Because if you used Go's gc then there wouldn't be any confusion about what language your program is written in.

> Is go called from C compiled or interpretted?

It's compiled. gccgo is a Go front-end for GCC. And GCC stands for GNU Compiler Collection.

答案3

得分: -2

在你的程序中,当你首次调用go函数时,编译器会生成必要的代码来进行函数调用,为函数参数分配空间,并存储有关函数参数类型的详细信息等等。
如果一切都符合编译器的标准,就会创建目标文件,然后进行其他进程,如链接等。
因此,基本上你不能说"go是从C编译还是解释执行",它是一系列协同工作的过程,使你的程序运行起来。

英文:

In your program when you first call the go function,the compiler will generate the necessary codes for function call,space for function arguments,store details about function arguments type etc.
If everything is correct as per the compiler standard,object file is created and further there are other processes like linking and all.
So basically you cannot say it as " Is go called from C compiled or interpretted?",it's a series of processes which works together to make your program run.

huangapple
  • 本文由 发表于 2015年4月1日 14:20:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/29384078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定