I am reading this post about time.startTimer declaration and definition.
From the answer, time.startTimer is declared in src/time/sleep.go
as follows:
func startTimer(*runtimeTimer)
And its definition is in src/runtime/time.go
as follows:
func startTimer(t *timer) {
if raceenabled {
racerelease(unsafe.Pointer(t))
}
addtimer(t)
}
So it seems that you can declare a function in one .go file and implement it in another .go file. I tried the same way, for example, declare a function in a.go and implement it in b.go, but it always failed when go run a.go
. Is that the correct way to do so? How can I declare a function that is implemented in another .go file? There is no import
in either sleep.go
or time.go
. How does Go do it?
Thanks