Function without body

700 views
Skip to first unread message

angan...@gmail.com

unread,
Jan 4, 2014, 1:22:42 AM1/4/14
to golan...@googlegroups.com
The language specification says:

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

I can understand the abs.go list the function as `func Abs(x float64) float64` without body because there are three files which implemented this function: abs_386.s, abs_arm.s, abs_amd64.s. 

But there is also a function in abs.go with the signature `func abs(x float64) float64` which is not exported, and I don't know where it is used.

Can someone please explain this for me? Thanks

angan...@gmail.com

unread,
Jan 4, 2014, 1:34:12 AM1/4/14
to golan...@googlegroups.com
I mean this Go source file from math package: https://code.google.com/p/go/source/browse/src/pkg/math/abs.go

andrey mirtchovski

unread,
Jan 4, 2014, 1:42:43 AM1/4/14
to angan...@gmail.com, golang-nuts
read the description for the CL that introduced it:

https://code.google.com/p/go/source/detail?r=af839530a31e

specifically that assembly implementations for unsupported
architectures may jump back to the pure go implementation.

i don't think (only briefly checked) there are any architectures that
aren't implementing all those basic functions in assembly, but that
doesn't mean there won't be others in the future.

Dave Cheney

unread,
Jan 4, 2014, 4:46:07 AM1/4/14
to andrey mirtchovski, angan...@gmail.com, golang-nuts
Some of the crypto/shaXXX implementations use a pure Go impl for 32bit platforms, they could be a good place to look.



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Caleb Doxsey

unread,
Jan 4, 2014, 6:11:35 PM1/4/14
to Dave Cheney, andrey mirtchovski, angan...@gmail.com, golang-nuts
Here's another example:


Go is case sensitive so Abs is different from abs.

For more info about assembly I have a full walkthrough here:

angan...@gmail.com

unread,
Jan 6, 2014, 4:54:48 PM1/6/14
to golan...@googlegroups.com, Dave Cheney, andrey mirtchovski
Thank you all for these good explanations. I'm very happy that Golang community has so many helpful and kindness experts here to help us.
Reply all
Reply to author
Forward
0 new messages