@satoru posted:
package main
import "fmt"
func main() {
i := 32
j := 32
fmt.Printf("%p is %p\n", &i, &i)
fmt.Printf("%p is not %p\n", &i, &j)
}
Output:
0xc000016100 is 0xc000016100
0xc000016100 is not 0xc000016108
Playground: https://play.golang.org/p/nXAEJeImeXa
However,
package main
import "fmt"
func main() {
i := 32
j := 32
fmt.Printf("i %p is i %p; i == i %t\n", &i, &i, &i == &i)
fmt.Printf("i %p is not j %p; i == j %t\n", &i, &j, &i == &j)
fmt.Println()
var v struct {
i struct{}
j struct{}
}
fmt.Printf("i %p is i %p; i == i %t\n", &v.i, &v.i, &v.i == &v.i)
fmt.Printf("i %p is not j %p; i == j %t\n", &v.i, &v.j, &v.i == &v.j)
}
Output:
i 0x40e020 is i 0x40e020; i == i true
i 0x40e020 is not j 0x40e024; i == j false
i 0x1e52bc is i 0x1e52bc; i == i true
i 0x1e52bc is not j 0x1e52bc; i == j true
Playground: https://play.golang.org/p/Wv814ZgPCul
package cmp
import "github.com/google/go-cmp/cmp"
Package cmp determines equality of values.
This package is intended to be a more powerful and safer alternative
to reflect.DeepEqual for comparing whether two values are semantically
equal.