【发布时间】:2020-11-09 12:13:14
【问题描述】:
我注意到函数throw中有一行*(*int)(nil) = 0
//go:nosplit
func throw(s string) {
// Everything throw does should be recursively nosplit so it
// can be called even when it's unsafe to grow the stack.
systemstack(func() {
print("fatal error: ", s, "\n")
})
gp := getg()
if gp.m.throwing == 0 {
gp.m.throwing = 1
}
fatalthrow()
*(*int)(nil) = 0 // not reached
}
*(*int)(nil) = 0 是什么意思?并且由于这条线*(*int)(nil) = 0 无法到达,为什么它在这里?有什么特殊用法吗?
【问题讨论】:
-
它是
panic("unreachable")的编译器内部变体。