13.2 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.Pointer
s 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:
Get The Go Programming Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.