I just want to look what variable datastructure is passed to the closure 
func   but I am confused with the assemble code 


// example.go

package main


import "time"


func main() {

s := []int{100, 200}

func() {

s[0] = 300

s = []int{300, 400}

}()

time.Sleep(1 * time.Second)

}



And I am confused with the assemble code 


"".main t=1 size=113 args=0x0 locals=0x38

0x0000 00000 (main.go:5) TEXT "".main(SB), $56-0

0x0000 00000 (main.go:5) MOVQ (TLS), CX

0x0009 00009 (main.go:5) CMPQ SP, 16(CX)

0x000d 00013 (main.go:5) JLS 106

0x000f 00015 (main.go:5) SUBQ $56, SP

0x0013 00019 (main.go:5) MOVQ BP, 48(SP)

0x0018 00024 (main.go:5) LEAQ 48(SP), BP

0x001d 00029 (main.go:5) FUNCDATA $0, 
gclocals·69c1753bd5f81501d95132d08af04464(SB)

0x001d 00029 (main.go:5) FUNCDATA $1, 
gclocals·2c033e7f4f4a74cc7e9f368d1fec9f60(SB)

0x001d 00029 (main.go:6) MOVUPS "".statictmp_0(SB), X0

0x0024 00036 (main.go:6) MOVUPS X0, "".autotmp_2+8(SP)

0x0029 00041 (main.go:6) LEAQ "".autotmp_2+8(SP), AX

0x002e 00046 (main.go:6) MOVQ AX, "".s+24(SP)

0x0033 00051 (main.go:6) MOVQ $2, "".s+32(SP)

0x003c 00060 (main.go:6) MOVQ $2, "".s+40(SP)

0x0045 00069 (main.go:6) LEAQ "".s+24(SP), AX

0x004a 00074 (main.go:10) MOVQ AX, (SP)

0x004e 00078 (main.go:10) PCDATA $0, $1

0x004e 00078 (main.go:10) CALL "".main.func1(SB)

0x0053 00083 (main.go:11) MOVQ $1000000000, (SP)

0x005b 00091 (main.go:11) PCDATA $0, $1

0x005b 00091 (main.go:11) CALL time.Sleep(SB)

0x0060 00096 (main.go:12) MOVQ 48(SP), BP

0x0065 00101 (main.go:12) ADDQ $56, SP

0x0069 00105 (main.go:12) RET

0x006a 00106 (main.go:12) NOP

0x006a 00106 (main.go:5) CALL runtime.morestack_noctxt(SB)

0x006f 00111 (main.go:5) JMP 0

在 2016年11月3日星期四 UTC+8下午2:43:40,Ian Lance Taylor写道:
>
> On Wed, Nov 2, 2016 at 8:03 PM, 刘桂祥 <liuguix...@gmail.com <javascript:>> 
> wrote: 
> > 
> > In golang closure func ,the needed outer variable is passed by reference 
> > 
> > but when the variable self is a reference in example.go , the closure 
> func 
> > paras is *[&map[int]int,...]  is so ? 
>
> I'm not completely sure what you are asking, but I think the answer is 
> yes. 
>
> > and I doubt what kind of datatype the paras in closure func? 
>
> Each function that has a closure has a custom type for the closure 
> variable.  It's essentially a struct each of whose fields is a pointer 
> to the type of the variable being closed over. 
>
> Ian 
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to