Pointers in Go

Pointers in Go

unsafe.Pointer

unsafe.Pointer can represent any pointer to an addressable value. It bridges pointer values and uintptr, letting us convert between the two.

Not addressable: Constants, basic type literals, functions and methods, arithmetic operation results, and most expression results are temporary. So they’re not addressable.

Map index result pointers are unsafe. Hash tables expand buckets and rearrange elements.

Chained method calls on pointer receiver temporaries can fail. Go takes the address of temporaries with & before calling methods.

The ++ operator requires addressable operands.

Pointer to uintptr: uintptr(unsafe.Pointer(p))