Golang 中的无实体函数 [英] Bodiless function in Golang

查看:50
本文介绍了Golang 中的无实体函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读math/floor.go的源代码,从第13行开始,我读了一些这样的代码:

Reading the source code of math/floor.go, starting from line 13, I read some code like this:

func Floor(x float64) float64

func floor(x float64) float64 {
    if x == 0 || IsNaN(x) || IsInf(x, 0) {
        return x
    }
    if x < 0 {
        d, fract := Modf(-x)
        if fract != 0.0 {
            d = d + 1
        }
        return -d
    }
    d, _ := Modf(x)
    return d
}

func Floor 似乎没有主体.我试图将这些代码复制并粘贴到我的 go 文件中.它不编译.错误消息是 missing function body.所以我的问题是:Go 语法中的无实体函数是否合法?谢谢.

It seems the func Floor has no body. I tried to copy and paste these code in my go file. it doesn't compile. The error message is missing function body. So my question is: is a bodiless function legal in Go's syntax? Thanks.

推荐答案

这是在程序集中实现函数的方式.您可以在 floor_ARCH.s 中找到程序集实现(例如:AMD64) 文件.

It's the way how functions are implemented in assembly. You find the assembly implementation in the floor_ARCH.s (e.g.: AMD64) files.

引用规范:

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

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

这篇关于Golang 中的无实体函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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