系统库 signal.go 中有这么一段代码:
// Wait until there are no more signals waiting to be delivered.
// Defined by the runtime package.
func signalWaitUntilIdle() //<-------------这里看不懂啊,我自己尝试模仿一个,报错说函数必须有函数体
func process(sig os.Signal) {
n := signum(sig)
if n < 0 {
return
}
handlers.Lock()
defer handlers.Unlock()
for c, h := range handlers.m {
if h.want(n) {
// send but do not block for it
select {
case c <- sig:
default:
}
}
}
// Avoid the race mentioned in Stop.
for _, d := range handlers.stopping {
if d.h.want(n) {
select {
case d.c <- sig:
default:
}
}
}
}
另外go里边可以嵌入汇编 所以你像下面这样定义一个方法也是合法的
add.go
```go
package add
func Add(a, b uint64) uint64
```
add.s
```
TEXT ·Add+0(SB),$0-24
MOVQ a+0(FP),BX
MOVQ b+8(FP),BP
ADDQ BP,BX
MOVQ BX,res+16(FP)
RET
```
#2
更多评论
你可以看看这个回答 https://stackoverflow.com/questions/14938960/what-does-a-function-without-body-mean
#1