Re: [go-nuts] why my program will panic?

2018-08-14 Thread Marvin Renich
* sheepbao [180814 10:53]: > Thank you for your detailed answer. > I thought it would crash in this line (b.Z = "zz") of code. But it dose not > happen and the program print "zz". > I don't understand why this program crash in return, not in b.Z = "zz". > Because I agree with your opinion, The

Re: [go-nuts] why my program will panic?

2018-08-14 Thread sheepbao
Thank you for your detailed answer. I thought it would crash in this line (b.Z = "zz") of code. But it dose not happen and the program print "zz". I don't understand why this program crash in return, not in b.Z = "zz". Because I agree with your opinion, The field Z of (*b) is beyond the memory

Re: [go-nuts] why my program will panic?

2018-08-14 Thread Marvin Renich
* sheepbao [180813 23:45]: > go version > go version go1.10.2 darwin/amd64 > > test code: > > func TestPoint(t *testing.T) { > type A struct { > X int > Y string > } > type B struct { > X int > Y string > Z string > } > > a := A{X: 2,

Re: [go-nuts] why my program will panic?

2018-08-13 Thread sheepbao
I just want to research how golang func stack work. On Tuesday, August 14, 2018 at 12:46:59 PM UTC+8, kortschak wrote: > > Why would you expect this to work? > > On Mon, 2018-08-13 at 20:44 -0700, sheepbao wrote: > > go version > > go version go1.10.2 darwin/amd64 > > > > test code: > > >

Re: [go-nuts] why my program will panic?

2018-08-13 Thread Dan Kortschak
Why would you expect this to work? On Mon, 2018-08-13 at 20:44 -0700, sheepbao wrote: > go version > go version go1.10.2 darwin/amd64 > > test code: > > func TestPoint(t *testing.T) { > type A struct { > X int > Y string > } > type B struct { > X int >    

[go-nuts] why my program will panic?

2018-08-13 Thread sheepbao
go version go version go1.10.2 darwin/amd64 test code: func TestPoint(t *testing.T) { type A struct { X int Y string } type B struct { X int Y string Z string } a := A{X: 2, Y: "yy"} b := (*B)(unsafe.Pointer()) b.Z = "zz"