https://golang.org/ref/spec#Comparison_operators
> Pointers to distinct zero-size variables may or may not be equal.

Looks like a more complicated example 
of https://github.com/golang/go/issues/8938.

On Friday, January 6, 2017 at 2:24:39 AM UTC-8, Ignazio Di Napoli wrote:
>
> I'm very curious about the answer to this unanswered StackOverflow 
> question: 
> http://stackoverflow.com/questions/41357948/what-golang-compiler-will-do-when-fmt-println
>
>
> import (
>     "fmt")
>
> type shout interface {
>     echo()}
>
> type a struct {}
> func (*a) echo () {
>     fmt.Println("a")}
>
> type b struct {}
> func (*b) echo () {
>     fmt.Println("b")}
>
> func compare(a, b shout) {
>     //fmt.Println(&a, &b)
>     if a == b {
>         fmt.Println("same")
>     } else {
>         fmt.Println("not same")
>     }}
>
> func main() {
>     a1 := &a{}
>     b1 := &b{}
>     a2 := &a{}
>     a1.echo()
>     b1.echo()
>     compare(a1, b1)
>     compare(a1, a2)
>     compare(a1, a1) }
>
>
> The output is different if a fmt.Println is commented or not. 
>
> Commented:
>
> not samenot same
> same
>
>
> Not commented:
>
> 0x1040a120 0x1040a128not same0x1040a140 0x1040a148
> same0x1040a158 0x1040a160
> same
>
>
>
> To me, it seems a compiler bug, or some undefined behaviour.
> Can someone help me understand?
>
>
> Thank you.
>
>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to