Skip to content

Instantly share code, notes, and snippets.

@cloverstd

cloverstd/main.go

Created Sep 24, 2020
Embed
What would you like to do?
access value via unsafe
func main() {
var i interface{} = 100
/**
type eface struct {
_type *_type
data unsafe.Pointer
}
*/
n := *(*int)(*(*unsafe.Pointer)(unsafe.Pointer(uintptr(unsafe.Pointer(&i)) + unsafe.Alignof(i))))
fmt.Println(n)
type eface struct {
_type uintptr // placeholder
data unsafe.Pointer
}
n = *(*int)((*eface)(unsafe.Pointer(&i)).data)
fmt.Println(n)
type eface2 struct {
_type uintptr // placeholder
data *int
}
n = *((*eface2)(unsafe.Pointer(&i)).data)
fmt.Println(n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.