I\'m working with this C struct on a 64 bit platform, trying to access the ui32v field in the value union:
struct _GNetSnmp
Sonia already answered her own question, I just want to provide the reason for why two type conversions are necessary.
From the documentation for unsafe.Pointer:
1) A pointer value of any type can be converted to a Pointer.
2) A Pointer can be converted to a pointer value of any type.
3) A uintptr can be converted to a Pointer.
4) A Pointer can be converted to a uintptr.
Since var ptr uint64
is not a pointer (as type uint64
is not a pointer), ptr
cannot be converted directly to unsafe.Pointer
using rule 1. Therefore it is necessary to first convert ptr
to uintptr
, then from uintptr
to a Pointer
following rule 3.