Makes sense, although I chuckled when I realized that the creator of that issue didn't actually have his issue resolved.
Creator: This behavior is undefined. Which one should it be? Go Team: Both. 😆 On Wed, May 4, 2022 at 12:46 PM Ian Lance Taylor <i...@golang.org> wrote: > On Tue, May 3, 2022 at 10:59 PM 'Axel Wagner' via golang-nuts > <golang-nuts@googlegroups.com> wrote: > > > >> As a tangent, I don't understand why this wasn't made unambiguous in > the language spec. Why not have `new(struct{})` always allocate a new > pointer? Who's allocating all these empty structs on the heap where this is > something that needs to be optimized for? Is that really worth complicating > the language? 🤔 > > > > > > I don't know why that decision was made. I do believe there are some > less obvious cases, where you at least have to add special casing in the > implementation (e.g. make([]T, x) would have to check at runtime if x is > 0). But I agree that it would probably be okay to change the spec here. > > Zero sized values are useful in Go, because they can have methods and > they can be stored in interfaces. But if the addresses of zero-sized > values must be distinct, then although zero-sized values appear to > have zero size they must in fact be implemented as taking up one byte. > For example, given `struct { a, b struct{} }`, the addresses of `a` > and `b` must be distinct, so that struct is actually two bytes. So, > sure, we could change it. But there are surprising results either > way. > > (Historically this was introduced for https://go.dev/issue/2620.) > > Ian > > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/b-WtVh3H_oY/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAOyqgcU%3DTdSF1co2jyeQuUhk2P7giwf33tdK6p%2Bd8UgaXO4Tng%40mail.gmail.com > . > -- 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/CAKbcuKgKhE1Mk8EcG889%3DjJpmk6EgAO2xbXbnVVkP3wUo7HGJA%40mail.gmail.com.