cast_test.go 696 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "fmt"
  4. "runtime"
  5. "testing"
  6. "unsafe"
  7. )
  8. type T1 struct {
  9. f1 int8 // 1 byte
  10. f2 int64 // 8 bytes
  11. f3 int32 // 4 bytes
  12. }
  13. type T2 struct {
  14. f1 int8 // 1 byte
  15. f3 int32 // 4 bytes
  16. f2 int64 // 8 bytes
  17. }
  18. func TestSizeOf(t *testing.T) {
  19. fmt.Println(runtime.GOARCH) // amd64
  20. t1 := T1{}
  21. fmt.Println(unsafe.Sizeof(t1)) // 24 bytes
  22. t2 := T2{}
  23. fmt.Println(unsafe.Sizeof(t2)) // 16 bytes
  24. }
  25. type People interface {
  26. Show1()
  27. }
  28. type Student struct {
  29. }
  30. func (*Student) Show1() {
  31. }
  32. func live() People {
  33. var su *Student
  34. return su
  35. }
  36. func TestPeople(t *testing.T) {
  37. b := live()
  38. fmt.Printf("%v \n", b)
  39. if b == nil {
  40. fmt.Println("a")
  41. } else {
  42. fmt.Println("b")
  43. }
  44. }