package main
import "fmt"
var a = 4
func main() {
fmt.Println(a, add(), a) //Output:8 8 8
}
func add() int {
a += 4
return a
}
示例的结果与spec中描述不符
When evaluating the operands of an expression, assignment, or return statement, all function calls, method calls, and communication operations are evaluated in lexical left-to-right order.
For example, in the assignment y[f()], ok = g(h(), i()+x[j()], <-c), k() the function calls and communication happen in the order f(), h(), i(), j(), <-c, g(), and k(). However, the order of those events compared to the evaluation and indexing of x and the evaluation of y is not specified.
Floating-point operations within a single expression are evaluated according to the associativity of the operators. Explicit parentheses affect the evaluation by overriding the default associativity. In the expression x + (y + z) the addition y + z is performed before adding x.
有疑问加站长微信联系(非本文作者)

参数传递时,压栈顺序和参数计算顺序不是一回事,而且是先计算再压栈。
fmt.Println接受的参数是interface,本质上是一种引用...