You're awesome! And Go's reflection is much better than what I've expected - and yes, I like it, I use it!
On Tuesday, September 6, 2016 at 12:57:45 AM UTC+4:30, Roberto Zanotto wrote: > > If you want a pointer instead of the direct value, just use New instead of > Zero: > v = reflect.New(fd.Type().Elem()).Interface() > > On Monday, September 5, 2016 at 9:30:13 PM UTC+2, dc0d wrote: >> >> Exactly! Thanks! Now, how to put it inside the pointer? I mean, how to >> get it's address and put that address inside the pointer variable? >> >> On Monday, September 5, 2016 at 10:47:23 PM UTC+4:30, Roberto Zanotto >> wrote: >>> >>> I should learn to read the questions more carefully before answering -_- >>> In the code you commented out, fd.Type() is a pointer type, so the zero >>> value of a pointer type is a nil pointer. >>> If you do fd.Type().Elem() it gives you the "dereferenced" type of the >>> value. >>> So, maybe you want: >>> v = reflect.Zero(fd.Type().Elem()).Interface() >>> >>> On Monday, September 5, 2016 at 7:28:13 PM UTC+2, dc0d wrote: >>>> >>>> How can I fill a pointer to point to the zero value of underlying type? >>>> >>>> Like in: >>>> >>>> if fd.Kind() == reflect.Ptr { >>>> if fd.IsNil() { >>>> // how to set v (pointer) to point to a zero value of underlying type? >>>> // using this: >>>> // v = reflect.Zero(fd.Type()).Interface() >>>> // still gives a nil value. >>>> } else { >>>> v = fd.Interface() >>>> } >>>> } >>>> >>>> >>>> >>>> I want to fill v with the zero value of the underlying direct type. >>>> >>> -- 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.