Go 为什么函数运行时参数可以这样表示?
此代码位于proc.go中。我不懂函数运行时参数,有人能帮我吗?对不起,我的英语很差Go 为什么函数运行时参数可以这样表示?,go,Go,此代码位于proc.go中。我不懂函数运行时参数,有人能帮我吗?对不起,我的英语很差 // Args hold the command-line arguments, starting with the program name. var Args []string func init() { if runtime.GOOS == "windows" { // Initialized in exec_windows.go. return }
// Args hold the command-line arguments, starting with the program name.
var Args []string
func init() {
if runtime.GOOS == "windows" {
// Initialized in exec_windows.go.
return
}
Args = runtime_args()
}
func runtime_args() []string // in package runtime
// Getuid returns the numeric user id of the caller.
//
// On Windows, it returns -1.
func Getuid() int { return syscall.Getuid() }
根据:
函数声明可以省略主体。这样的声明为在Go之外实现的函数(如汇编例程)提供签名
在您的例子中,此函数实现实际上是在运行时
包中声明的
:
:
...
func runtime_args() []string // in package runtime
...
...
//go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string { return append([]string{}, argslice...) }
...