"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Are Some Go Functions, Like `math.Floor`, Bodiless?

Why Are Some Go Functions, Like `math.Floor`, Bodiless?

Published on 2025-01-29
Browse:971

Why Are Some Go Functions, Like `math.Floor`, Bodiless?

Bodiless Functions in Go

The provided code presents a peculiar situation where the Floor function appears bodiless, lacking a function body. This can be encountered when examining the source code of math/floor.go.

Upon investigation, it becomes clear that this phenomenon is intentional. In Go, bodiless functions are permitted for implementations written in assembly. The actual implementation can be found in the floor_ARCH.s files (e.g., for AMD64).

As stated in the Go specification:

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

This provision allows low-level functions to be defined in assembly while maintaining a consistent, well-typed Go interface.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3