You can also see various errors you may get when using init in golang/test/init.go
Now cmd/compile/internal/gc/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 itself is controlled by golang/cmd/gc/init.c :
/* * 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". */
Its use is illustrated in " When does the init() function run in go (golang)? "
Vonc
source share