>> Note that there are two distinct variables involved (a and b). You’re right. I misread this.
> On Feb 26, 2024, at 1:15 PM, Axel Wagner <axel.wagner...@googlemail.com> > wrote: > > On Mon, Feb 26, 2024 at 7:25 PM Brien Colwell <xcolw...@gmail.com > <mailto:xcolw...@gmail.com>> wrote: >> Interesting. That seems to break the comparable spec. >> >> >> Pointer types are comparable. Two pointer values are equal if they point >> >> to the same variable or if both have value nil. Pointers to distinct >> >> zero-size variables may or may not be equal. > > How do you think this is broken? Note that there are two distinct variables > involved (a and b). Pointers to distinct variables are allowed to be equal, > or not to be equal. > >> >> it would be valid for `==` on pointers to zero-sized types to always >> >> evaluate to `true`, >> >> This would be more straightforward behavior. >> >> >> >>> On Feb 26, 2024, at 9:24 AM, tapi...@gmail.com <mailto:tapi...@gmail.com> >>> <tapir....@gmail.com <mailto:tapir....@gmail.com>> wrote: >>> >>> package main >>> >>> var a, b [0]int >>> var p, q = &a, &b >>> >>> func main() { >>> if (p == q) { >>> p, q = &a, &b >>> println(p == q) // false >>> } >>> } >>> >>> On Thursday, February 22, 2024 at 6:55:49 PM UTC+8 Brien Colwell wrote: >>>> I'm confused by this output. It appears that the interface of two >>>> different pointers to an empty struct are equal. In all other cases, >>>> interface equality seems to be the pointer equality. What's going on in >>>> the empty struct case? >>>> >>>> ``` >>>> package main >>>> >>>> import "fmt" >>>> >>>> type Foo struct { >>>> } >>>> >>>> func (self *Foo) Hello() { >>>> } >>>> >>>> type FooWithValue struct { >>>> A int >>>> } >>>> >>>> func (self *FooWithValue) Hello() { >>>> } >>>> >>>> type Bar interface { >>>> Hello() >>>> } >>>> >>>> func main() { >>>> a := &Foo{} >>>> b := &Foo{} >>>> fmt.Printf("%t\n", *a == *b) >>>> fmt.Printf("%t\n", a == b) >>>> fmt.Printf("%t\n", Bar(a) == Bar(b)) >>>> >>>> c := &FooWithValue{A: 1} >>>> d := &FooWithValue{A: 1} >>>> fmt.Printf("%t\n", *c == *d) >>>> fmt.Printf("%t\n", c == d) >>>> fmt.Printf("%t\n", Bar(c) == Bar(d)) >>>> } >>>> ``` >>>> >>>> Prints (emphasis added on the strange case): >>>> >>>> ``` >>>> true >>>> false >>>> **true** >>>> true >>>> false >>>> false >>>> ``` >>>> >>>> >>> >>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "golang-nuts" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/golang-nuts/JBVqWYFdtC4/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> golang-nuts+unsubscr...@googlegroups.com >>> <mailto:golang-nuts+unsubscr...@googlegroups.com>. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/6fc9b600-6707-414c-b19b-e5e14919c5a5n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/golang-nuts/6fc9b600-6707-414c-b19b-e5e14919c5a5n%40googlegroups.com?utm_medium=email&utm_source=footer>. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com >> <mailto:golang-nuts+unsubscr...@googlegroups.com>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/E875D5D3-FFB2-40BA-B930-A10461A2998E%40gmail.com >> >> <https://groups.google.com/d/msgid/golang-nuts/E875D5D3-FFB2-40BA-B930-A10461A2998E%40gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/BF01D7A5-36A9-48A7-B35A-E18C81CF4A1E%40gmail.com.