The language spec seems to allow a1 and a2 to have the same address but 
doesn't require that to be always the case.

At the one hand:

*Taking the address of a composite literal generates a pointer to a unique 
variable initialized with the literal's value. *[Composite Literals]


On the other hand:

*Two distinct zero-size variables may have the same address in memory. *[Size 
and alignment guarantees]


The former statement would always require a1 and a2 to be different, but 
the latter allows them to be equal without requiring that always to be the 
case. So according to the language spec this is not a bug.

Here is a smaller program which shows both behaviors depending on a1.echo() 
commented out or not.

package main

import (
        "fmt"
)

type a struct{} 
 
func (*a) echo() {
        fmt.Println("a")
}

func main() {
        a1 := &a{}
        a2 := &a{}
        // a1.echo()
        if a1 == a2 {
                fmt.Println("a1 == a2")
        } else {
                fmt.Println("a1 != a2")
        }
}

>

-- 
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