Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-26 Thread Ian Lance Taylor
On Tue, Jun 25, 2024 at 9:37 PM 'Axel Wagner' via golang-nuts wrote: > > you might be interested to learn that Ian has filed a CL adding an FAQ entry. Now committed at https://go.dev/doc/faq#zero_size_types . Ian -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-25 Thread 'Axel Wagner' via golang-nuts
Hi, you might be interested to learn that Ian has filed a CL adding an FAQ entry . On Thu, 20 Jun 2024 at 16:18, Oliver Eikemeier wrote: > Thanks for that example. > > The issue is that you and I have constructed aliased variables that the

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread 'Axel Wagner' via golang-nuts
I want to re-emphasise that both of these examples violate the allowed usages of unsafe.Pointer defined by gc. So I would argue that, yes, its expectation is reasonable, because it explicitly told you not to create this situation. If you can construct a program that does not violate the

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Oliver Eikemeier
> Am 20.06.2024 um 14:12 schrieb Axel Wagner : > > On Thu, 20 Jun 2024 at 13:48, Oliver Eikemeier > wrote: > > I think you should acknowledge that the spec *is* already trying to be very > clear about this. The fact that you can poke holes in it is because

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Robert Engels
What I asked did not require the first, I was referring more about the latter. So regardless of how it is implemented it is always false. On Jun 20, 2024, at 7:39 AM, Axel Wagner wrote:On Thu, 20 Jun 2024 at 14:21, Robert Engels wrote:I would add that I think the Go team

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread 'Axel Wagner' via golang-nuts
FYI, filed https://github.com/golang/go/issues/68086 for the spec-hole that conversions between unsafe.Pointer and other pointer types are not implementation defined. On Thu, 20 Jun 2024 at 14:12, Axel Wagner wrote: > > > On Thu, 20 Jun 2024 at 13:48, Oliver Eikemeier < >

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Robert Engels
I would add that I think the Go team should strive to remove as much “implementation defined” or “undefined” from the spec as possible. Forgo the optimizations. It’s this language that makes C++ such a pain to work with especially in a cross platform manner. I think you can safely narrow the spec

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread 'Axel Wagner' via golang-nuts
On Thu, 20 Jun 2024 at 13:48, Oliver Eikemeier wrote: > > Am 20.06.2024 um 13:24 schrieb Axel Wagner >: > > We can see that 1. `unsafe.Pointer` is definitionally a pointer type, 2. > in your example, the two `unsafe.Pointers` do not point to the same > variable and do not have the value `nil`

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Oliver Eikemeier
> Am 20.06.2024 um 13:24 schrieb Axel Wagner : > > We can see that 1. `unsafe.Pointer` is definitionally a pointer type, 2. in > your example, the two `unsafe.Pointers` do not point to the same variable and > do not have the value `nil` and 3. are not pointing at distinct zero-sized >

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Jan Mercl
On Thu, Jun 20, 2024 at 1:26 PM 'Axel Wagner' via golang-nuts wrote: > (apologies for the abundance of grammatical and spelling errors that occurred > during editing and of course only became visible after hitting "send") (Send collapses the wave function ;-) -- You received this message

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread 'Axel Wagner' via golang-nuts
(apologies for the abundance of grammatical and spelling errors that occurred during editing and of course only became visible after hitting "send") On Thu, 20 Jun 2024 at 13:24, Axel Wagner wrote: > On Thu, 20 Jun 2024 at 12:28, Oliver Eikemeier < > eikeme...@fillmore-labs.com> wrote: > >> Let

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Jan Mercl
On Thu, Jun 20, 2024 at 1:16 PM Oliver Eikemeier wrote: > • Pointer types are comparable. Two pointer values are equal if they point to > the same variable or if both have value nil. Pointers to distinct zero-size > variables may or may not be equal. Compare to (made up) "NaNs always compare

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread 'Axel Wagner' via golang-nuts
On Thu, 20 Jun 2024 at 12:28, Oliver Eikemeier wrote: > 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

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Oliver Eikemeier
https://go.dev/ref/spec#Comparison_operators • Pointer types are comparable. Two pointer values are equal if they point to the same variable or if both have value nil. Pointers to distinct zero-size variables may or may not be equal. Another example (Go Playground

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Jan Mercl
On Thu, Jun 20, 2024 at 12:28 PM Oliver Eikemeier wrote: > 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. The plural is there

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-20 Thread Oliver Eikemeier
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

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-19 Thread 'Axel Wagner' via golang-nuts
On Wed, 19 Jun 2024 at 22:43, Oliver Eikemeier 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

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-19 Thread Oliver Eikemeier
Hi, Ian Lance Taylor schrieb am Mittwoch, 19. Juni 2024 um 19:19:09 UTC+2: On Wed, Jun 19, 2024 at 9:59 AM Oliver Eikemeier wrote: > The specification says: “Pointers to distinct zero-size variables may or may not be equal.” The specs says, as you say above, "Pointers to distinct

Re: [go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-19 Thread Ian Lance Taylor
On Wed, Jun 19, 2024 at 9:59 AM Oliver Eikemeier wrote: > > I'm observing some strange behavior and could use some help understanding it. > > The specification says: “Pointers to distinct zero-size variables may or may > not be equal.” > > With the following program (Go Playground): > > var ( a

[go-nuts] Comparison of pointers to distinct zero-sized variables

2024-06-19 Thread Oliver Eikemeier
I'm observing some strange behavior and could use some help understanding it. The specification says: *“Pointers to distinct zero-size variables may or may not be equal.”* With the following program (Go Playground