Created
March 22, 2020 15:58
-
-
Save xpzouying/276b4329e72e16ddd06996d247ed16c0 to your computer and use it in GitHub Desktop.
example-go-unsafe-pointer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | |
} |
Author
xpzouying
commented
Mar 22, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment