Skip to content
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

Zero-width type weirdness #34897

Closed
thwd opened this issue Oct 14, 2019 · 3 comments
Closed

Zero-width type weirdness #34897

thwd opened this issue Oct 14, 2019 · 3 comments

Comments

@thwd
Copy link

thwd commented Oct 14, 2019

What version of Go are you using (go version)?

$ go version
go1.13.1

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
playground

What did you do?

I ran two slightly different programs:

What did you expect to see?

Spec says "Pointers to distinct zero-size variables may or may not be equal."

I expected the answer of whether they are to be a compiler implementation decision and not behavior that changes depending on the input program.

What did you see instead?

I see that two zero-width values are equal only when they are otherwise used. They are treated as unequal otherwise.

@cherrymui
Copy link
Member

Implementation detail: what matters is whether the zero-width object is heap allocated or stack allocated. In some sense it is still the compiler's decision, but this decision is made depending on the input program.

Anyway, as the spec says, this is work-as-intended.

@cherrymui
Copy link
Member

Also, I should mention, this decision may change on different versions of Go.

@randall77
Copy link
Contributor

Indeed, working as intended. Or at least, spec'd.

@golang golang locked and limited conversation to collaborators Oct 13, 2020
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