I'm watching lectures about Go. One about stack growing with this example:
package main
import "fmt"
const size = 1024
func main() {
fmt.Println("Start")
s:= "HELLO"
stackCopy(&s, 0, [size]int{})
}
func stackCopy(s *string, c int, a [size]int){
println("println: ", s, *s)
//fmt.Println("fmt: ", s, *s)
c++
if c == 10 {
return
}
stackCopy(s, c, a)
}
When use only println, address of "s" change (stack is growing and data move to other place):
Start
println: 0xc000107f58 HELLO
println: 0xc000107f58 HELLO
println: 0xc000117f58 HELLO
println: 0xc000117f58 HELLO
println: 0xc000117f58 HELLO
println: 0xc000117f58 HELLO
println: 0xc00019ff58 HELLO
println: 0xc00019ff58 HELLO
println: 0xc00019ff58 HELLO
println: 0xc00019ff58 HELLO
When I mix println and fmt.Println or only fmt.Println adress of "s" not change:
Start
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
println: 0xc00010a040 HELLO
fmt: 0xc00010a040 HELLO
Why this happen?