2 回答

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊
您還可以查看使用initin時(shí)可能遇到的不同錯(cuò)誤golang/test/init.go
// Verify that erroneous use of init is detected.
// Does not compile.
package main
import "runtime"
func init() {
}
func main() {
init() // ERROR "undefined.*init"
runtime.init() // ERROR "unexported.*runtime\.init"
var _ = init // ERROR "undefined.*init"
}
init本身由golang/cmd/gc/init.c:
現(xiàn)在在cmd/compile/internal/gc/init.go:
/*
* a function named init is a special case.
* it is called by the initialization before
* main is run. to make it unique within a
* package and also uncallable, the name,
* normally "pkg.init", is altered to "pkg.init·1".
*/
- 2 回答
- 0 關(guān)注
- 195 瀏覽
添加回答
舉報(bào)