| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package main
- import (
- "fmt"
- "runtime"
- "testing"
- "unsafe"
- )
- type T1 struct {
- f1 int8 // 1 byte
- f2 int64 // 8 bytes
- f3 int32 // 4 bytes
- }
- type T2 struct {
- f1 int8 // 1 byte
- f3 int32 // 4 bytes
- f2 int64 // 8 bytes
- }
- func TestSizeOf(t *testing.T) {
- fmt.Println(runtime.GOARCH) // amd64
- t1 := T1{}
- fmt.Println(unsafe.Sizeof(t1)) // 24 bytes
- t2 := T2{}
- fmt.Println(unsafe.Sizeof(t2)) // 16 bytes
- }
- type People interface {
- Show1()
- }
- type Student struct {
- }
- func (*Student) Show1() {
- }
- func live() People {
- var su *Student
- return su
- }
- func TestPeople(t *testing.T) {
- b := live()
- fmt.Printf("%v \n", b)
- if b == nil {
- fmt.Println("a")
- } else {
- fmt.Println("b")
- }
- }
|