Hi Lee, All the defer functions are pushed into stack. When unwinding the stack , the last function pushed comes out first and hence you see the execution order is reversed
On Sun, Jun 26, 2022 at 2:11 AM Lee Chou <mozartz.2...@gmail.com> wrote: > Hello, > > https://go.dev/play/p/J1tVplkIrjt > > why o1.Ref print `2` but p1.Ref print `1` ? > why o1.Ref print `2` but o2.NonRef print `3` ? it's so confused. > > -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/19cbb40a-b21a-4dd5-964d-7921095de33dn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/19cbb40a-b21a-4dd5-964d-7921095de33dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CA%2BikOXVuKKAWpv4QPCiF4qntex4iFeFfR1C7A9seeEzmOBvW6g%40mail.gmail.com.