package main
func main() {
b := []int{1}
bb := make([]*int, 0, 1)
for k, v := range b {
_ = &v //8 line
_ = &b[k] //9 line
// bb = append(bb, &v)
bb = append(bb, &b[k])
}
// for _, v := range bb {
// fmt.Println(*v)
// }
}
1、When i use `go too compile -N -l -S main.go |grep "main.go:8" ` print asm
on line 8, it print nothing.
2、When i use `go too compile -N -l -S main.go |grep "main.go:9" ` print asm
on line 8, it print some asm code:
0x0136 00310
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) MOVQ
"".b+168(SP), CX
0x013e 00318
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) CMPQ
"".k+72(SP), CX
0x0143 00323
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) JCS
330
0x0145 00325
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) JMP
583
0x0247 00583
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) CALL
runtime.panicindex(SB)
0x024c 00588
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) UNDEF
0x024e 00590
(/data/app/go/src/gosrc/demo/base_learn/slice/range/main.go:9) NOP
so it because a copy of the array/slice variable ?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.