假设有一个字符串保存类型变量的地址,我们可以将此地址解析成这样吗?uint64
*uint64
例如:
i := uint64(23473824)
ip := &i
str := fmt.Sprintf("%v", ip)
u, _ := strconv.ParseUint(str, 0, 64)
u是uint64,该如何从这个值中取出指针?
假设有一个字符串保存类型变量的地址,我们可以将此地址解析成这样吗?uint64
*uint64
例如:
i := uint64(23473824)
ip := &i
str := fmt.Sprintf("%v", ip)
u, _ := strconv.ParseUint(str, 0, 64)
u是uint64,该如何从这个值中取出指针?
You can do it with
ip = (*uint64)(unsafe.Pointer(uintptr(u)))
Albeit I don't know what guarantees Go gives you about the validity of such a pointer, nor can I think of any use case where this code should be used..