pointers - Assigning a type uintptr to uint64 in GoLang -
i'm trying assign value found in variable of type uintptr uint64 variable in go. using
myvar = valfromsystem
gives me
cannot use valfromsystem (type uintptr) type uint64 in assignment
and trying
myvar = *valfromsystem
gives me
invalid indirect of valfromsystem (type uintptr)
is there way pull value pointed valfromsystem assign myvar?
first, cast valfromsystem
unsafe.pointer
. unsafe.pointer
can casted pointer type. next, cast unsafe.pointer
pointer whatever type of data valfromsystem
points to, e.g. uint64
.
ptrfromsystem = (*uint64)(unsafe.pointer(valfromsystem))
if want value of pointer (without dereferencing it), can use direct cast:
uint64fromsystem = uint64(valfromsystem)
though remember should use type uintptr
when using pointers integers.
Comments
Post a Comment