drbvm26000 2013-02-18 14:47
浏览 24
已采纳

没有身体的功能是什么意思?

I'm reading the code that package time, and then I want to know how the func After(d Duration) <-chan Time works.

I found the code follows:

func After(d Duration) <-chan Time {
    return NewTimer(d).C
}

func NewTimer(d Duration) *Timer {
    c := make(chan Time, 1)
    t := &Timer{
        C: c,
        r: runtimeTimer{
            when: nano() + int64(d),
            f:    sendTime,
            arg:  c,
        },
    }
    startTimer(&t.r)
    return t
}

So I found the definition of startTimer - it's so weird that function startTimer does not have a function body.

func startTimer(*runtimeTimer)

I want to know that :

  1. Where is the real code of startTimer
  2. Why an "abstract method" can exists here
  3. Why the author of Go wrote it like this

Thanks!

  • 写回答

1条回答 默认 最新

  • douzhong5902 2013-02-18 15:02
    关注

    1) The function is defined here:

    // startTimer adds t to the timer heap.
    //go:linkname startTimer time.startTimer
    func startTimer(t *timer) {
        if raceenabled {
            racerelease(unsafe.Pointer(t))
        }
        addtimer(t)
    }
    

    2) Function declarations:

    A function declaration may omit the body. Such a declaration provides the signature for a function implemented outside Go, such as an assembly routine.

    3) Not every programming language can express its own runtime entirely (C can, for example). Parts of the Go runtime and the standard library are in C, parts are in assembly while some other are in .goc, which is a not well documented hybrid of Go and C.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型