-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Milestone
Description
version: go version go1.5 darwin/amd64
There is an example about variable initialization order in the go specs:
var (
a = c + b
b = f()
c = f()
d = 3
)
func f() int {
d++
return d
}
the spec gives the initialization order is d, b, c, a. but the result of above example is not the same as the order spec gives.
package main
import "fmt"
var (
a = c + b
b = f()
c = f()
d = 3
)
func f() int {
d++
return d
}
func main() {
fmt.Println(a, b, c, d)
}
$go run example.go
9 5 4 5
according to the result, the actual init order should be d ,c ,b, a, not the same as the order in spec.