Let me start with this: I’m fine with the behavior, it is exotic enough that even the optimizer should be allowed to assume something that doesn’t hold during runtime, since it simplifies things.
What I think is at least surprising and at worst lacking is the documentation. It mentions “pointers” (plural) to zero-sized variables, but for this behavior it is sufficient when only one pointer derives from a pointer to a zero-sized variable, as demonstrated in the example below. I’m advocating for at least a FAQ article, but also think the specification should be adapted, for clarity but also for the fact that only one pointer pointing to a zero-sized variable can compare differently to anything over time, even things having the same address value. I do not believe the specification is clear on this. Otherwise I don’t think this is urgent. But it seems to pop up repeatedly. Cheers Oliver > Am 19.06.2024 um 23:16 schrieb 'Axel Wagner' via golang-nuts > <golang-nuts@googlegroups.com>: > > The spec says both. It says >> Two distinct zero-size variables may have the same address in memory. > And it says >> Pointers to distinct zero-size variables may or may not be equal. > > The former means what you say. The latter means what Ian says. > >> Then I have two pointers. Where in the spec is “the result of comparison of >> pointers may change over time”? >> >> For example (Go Playground <https://go.dev/play/p/acknRHBvi0P>): >> >> func f3() { >> var ( >> a struct{} >> b int >> aa = unsafe.Pointer(&a) >> ba = unsafe.Pointer(&b) >> eq = aa == ba >> ) >> >> println("&a:", aa) >> println("&b:", ba) >> println("&a == &b:", eq) >> } >> >> gives >> >> &a: 0xc000046738 >> &b: 0xc000046738 >> &a == &b: false >> >> and &b is not even a pointer to a zero-sized variable. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/60900D25-852D-4A9F-904F-D2ECFF47576D%40fillmore-labs.com.