On Wed, 19 Jun 2024 at 22:43, Oliver Eikemeier <eikeme...@gmail.com> wrote:

> The specs says, as you say above, "Pointers to distinct zero-size
> variables may or may not be equal.” That means that you can't predict
> the result of any given comparison of addresses of zero-sized
> variables.
>
>
> I'm not sure I read it that way. I would interpret it as *“taking pointer
> to distinct zero-size variables may or may not result in equal pointers”*.
>
> But not being able to have a *repeatable* result of a pointer comparison
> seems strange to me. The specification says “you'll get *some* pointers”.
> Fine.
>

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.
>
> Could be true, could be false, could change each time you
> do the comparison. So this behavior is permitted by the spec.
>
>
> I'm not sure about the “undefined behavior *over time*”. I get that the
> compiler lays out the memory however it sees fit, but then I should have
> unchanging values in my variables.
>
>
> > The interesting part here is that I can create two pointers (which may
> or may not be equal per specification), but depending on how I compare them
> I get different results.
>
> Yes, as the spec permits.
>
>
>  I assume this has little relevance in practice, but it is surprising.
>
> --
> 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/64e58302-59a6-4cbf-859e-aa6b8a2b6068n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/64e58302-59a6-4cbf-859e-aa6b8a2b6068n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfE6bzYQJ7s_GHEN7%3Dp3s2p0pSWNMgcw8t4tTiSy04ucFg%40mail.gmail.com.

Reply via email to