0

I want to figure out, what happened underneath in golang, when converting a var to interface{}.

I recently is reading source of golang/src/reflect/type.go, and I couldnot understand the code in Line 1050, here is the code:

// Create a new ptrType starting with the description
// of an *unsafe.Pointer.
p = new(ptrType)
var iptr interface{} = (*unsafe.Pointer)(nil)
prototype := *(**ptrType)(unsafe.Pointer(&iptr))
*p = *prototype

I think the key is the behavior of assigning data to interface{}, can anyone help?

ispe54
  • 9
  • 1
  • Seems to fit the two values within a pointer that I mention in http://stackoverflow.com/a/23148998/6309. – VonC Dec 08 '14 at 13:02
  • 6
    This is not the best way to understand interfaces. You might want to take a look at http://research.swtch.com/interfaces instead. This might no longer be perfectly accurate in all cases or on all platforms but will definitely enlighten you more than wading through package reflect's source. – Volker Dec 08 '14 at 13:12

0 Answers0