Skip to content

Spec does not explain comparing pointers to zero-sized objects #2620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ianlancetaylor opened this issue Dec 26, 2011 · 3 comments
Closed

Spec does not explain comparing pointers to zero-sized objects #2620

ianlancetaylor opened this issue Dec 26, 2011 · 3 comments
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

As far as I can see, the spec does not let me predict the result of this program.  The
spec doesn't say anything clearly about comparing two pointers to zero-sized objects.

Both 6g and gccgo current print "true", so I would vote for formalizing that.

package main

type S struct { }
type A [10]S

func main() {
    var a A
    p1 := &a[0]
    p2 := &a[1]
    if p1 == p2 {
        println("true")
    } else {
        println("false")
    }
}
@ianlancetaylor
Copy link
Contributor Author

Comment 1:

Owner changed to @griesemer.

@rsc
Copy link
Contributor

rsc commented Jan 9, 2012

Comment 2:

The spec should make clear that while it is permissible
for pointers to distinct 0-sized objects to compare equal,
it is also permissible for them to compare unequal.
No guarantee is made.
For example,
x := make([]struct{}, 10)
y := make([]struct{}, 10)
&x[0] == &y[1]?  Maybe.
Russ

@griesemer
Copy link
Contributor

Comment 3:

This issue was closed by revision 1320ce0.

Status changed to Fixed.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants