October 2015
Beginner to intermediate
400 pages
14h 44m
English
unsafe.Pointer
Most pointer types are written *T, meaning “a pointer to a variable
of type T.” The unsafe.Pointer type is a special kind of pointer that can
hold the address of any variable. Of course, we can’t indirect through an
unsafe.Pointer using *p because we don’t know what type that
expression should have. Like ordinary pointers, unsafe.Pointers are
comparable and may be compared with nil, which is the zero value of
the type.
An ordinary *T pointer may be converted to an
unsafe.Pointer, and an unsafe.Pointer may be converted back
to an ordinary pointer, not necessarily of the same type *T.
By converting a *float64 pointer to a *uint64, for
instance, we can inspect the bit pattern of a floating-point variable: