【发布时间】:2018-05-03 02:31:13
【问题描述】:
func main() {
var a = math.MaxInt64
fmt.Println(a + 1) //-9223372036854775808
fmt.Println(math.MaxInt64 + 1) //constant 9223372036854775808 overflows int
}
why the two ways perform differently?
【问题讨论】:
-
让你运行你的程序,它给两个溢出错误
-
一个是常量,另一个是变量。一个在编译时评估,另一个在运行时评估。在博客中了解 Go 中的常量。