源代码缺少函数体,它是如何编译的?

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

Source missing function body, how is it compiling?

问题

在Go语言的源代码中,我看到一个没有任何函数体的函数声明。

https://github.com/golang/go/blob/master/src/math/log10.go#L9

func Log10(x float64) float64

但是当我尝试相同的操作时,它给我一个错误:missing function body for __。

https://play.golang.org/p/Ncp-0-8vHB

这在Go源代码中是如何工作的?我的意思是math包是如何编译的?这个源文件只是用于文档目的吗?

看起来Log10是log10的公共/暴露版本,但是在语言中没有"getter"约定或类似的东西,那么Log10的函数体在哪里声明的?

英文:

In the Go lang source code, I see a function declared without any body.
https://github.com/golang/go/blob/master/src/math/log10.go#L9

<!-- language: lang-go -->

func Log10(x float64) float64

But when I do the same it gives me an error: missing function body for __

https://play.golang.org/p/Ncp-0-8vHB

How is this working in the Go source code? I mean how is the math package compiling? Is this source file just for documentation purposes?

It seems like Log10 is a public/exposed version of log10, but there is no "getter" convention or anything like that in the language, so where is the body of Log10 declared???

答案1

得分: 5

这是在同一个包中的*.s文件中为各种架构定义的汇编代码。

根据规范

> 函数声明可以省略函数体。这样的声明为在Go之外实现的函数(如汇编例程)提供了函数签名。

英文:

It is defined in assembly for various architectures in the *.s files located in the same package.

Per the spec:

> A function declaration may omit the body. Such a declaration provides the signature for a function implemented outside Go, such as an assembly routine.

huangapple
  • 本文由 发表于 2017年6月26日 23:41:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/44763440.html
匿名

发表评论

匿名网友

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

确定