9ce192f0e56cbb7eec5a28a85aede51b4e6b464b.svn-base 300 B

123456789101112131415161718192021
  1. package main
  2. import (
  3. "fmt"
  4. "unsafe"
  5. )
  6. type object struct {
  7. f float64
  8. i int32
  9. }
  10. func main() {
  11. obj := &object{
  12. f: 1.0,
  13. i: 1,
  14. }
  15. f := (*float64)(unsafe.Pointer(obj))
  16. fmt.Println(*f) //1
  17. fmt.Println(unsafe.Pointer(obj) == unsafe.Pointer(f)) //true
  18. }