Bodiless function in Golang

后端 未结 2 1165
广开言路
广开言路 2020-12-11 15:19

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 {
          


        
相关标签:
2条回答
  • 2020-12-11 15:52

    In my case I had "../../../pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/go/ssa/interp/testdata/src/fmt/fmt.go:3:6: missing function body" error!

    and it was because I used fmt without importing it so my IDE imported the wrong package

    I fixed it by removing the fmt import and just importing "fmt"

    0 讨论(0)
  • 2020-12-11 16:07

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

    To quote 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.

    0 讨论(0)
提交回复
热议问题