Skip to content

Instantly share code, notes, and snippets.

@xpzouying
Created March 22, 2020 15:58
Show Gist options
  • Save xpzouying/276b4329e72e16ddd06996d247ed16c0 to your computer and use it in GitHub Desktop.
Save xpzouying/276b4329e72e16ddd06996d247ed16c0 to your computer and use it in GitHub Desktop.
example-go-unsafe-pointer
package main
import (
"log"
"unsafe"
)
func main() {
x := make([]byte, 8)
x[0] = 3
x[4] = 1
addr := unsafe.Pointer(&x[0])
log.Print(*(*uint64)(addr))
log.Print((*[2]uint32)(addr)[0])
log.Print((*[2]uint32)(addr)[1])
}
@xpzouying
Copy link
Author

(base) ➜  go run main.go
2020/03/22 23:56:53 4294967299
2020/03/22 23:56:53 3
2020/03/22 23:56:53 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment