In reflection package I see the code like
return float64(*(*float32)(v.ptr))
What is *(*float32)(v.ptr)? I don't have any ideas
In reflection package I see the code like
return float64(*(*float32)(v.ptr))
What is *(*float32)(v.ptr)? I don't have any ideas
Let's unwrap the expression. We'll take it from innermost to outermost, since that's the order it's evaluated:
(*float32)(v.ptr)
Convert v.ptr
to *float32
, a pointer to a float32
.
*(*float32)(v.ptr)
Dereference that pointer, giving us a float32
value.
float64(*(*float32)(v.ptr))
Convert the float32
value to a float64
value.
So, whatever v.ptr
is, it's converted to a float32
pointer, dereferenced, and then converted to float64
, and returned.