You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that there is some inconsistent optimization that causes the difference. I think that it is more useful for empty anonymous structs to generate unique addresses.
The text was updated successfully, but these errors were encountered:
Passing x or y to fmt.Printf causes the anonymous structs to escape. They are as a result allocated by the runtime. All zero-sized objects allocated by the runtime are given the same address.
If you don't pass x or y to fmt.Printf, then the anonymous structs they reference are "allocated" on the stack. They happen to get the same address in this instance.
Your middle case generates one runtime allocation and one stack allocation, which is why they are not equal.
I agree that having &struct{}{} generate unique addresses would be marginally more useful than the current situation. But the only way I see to implement that is to treat struct{} as a 1-byte type. At that point, you might as well use a byte object instead (in cases where you care). So I don't see a compelling reason why we should introduce special cases for struct{} into the language.
Closing, as I don't think there's anything to do here. This has been discussed at length in the past, which led to https://golang.org/cl/5528053 (fixing #2620). See discussions there.
Let's talk about the following code. The difference among a()/b()/c() is the print output.
Here goes the output.
It seems that there is some inconsistent optimization that causes the difference. I think that it is more useful for empty anonymous structs to generate unique addresses.
The text was updated successfully, but these errors were encountered: