Good question. And yes, there is a reason not to use a pointer to the empty struct: They're all identical! So this would actually make the problem worse, not better. See it in the playground: go.dev/play/p/8OoLFRu3NnM
@boldlygo thank you for that info. Is this behaviour documented somewhere? Can't find it in the spec at first glance. And another thing - would pointers to the empty structs of different types work? - watching it in the playground, no. Very interesting behaviour. BTW loving your podcast 👌
The relevant sentence in the spec reads "Two distinct zero-size variables may have the same address in memory." IOW, it's not guaranteed. An implementation may choose to have pointers to two empty structs (or other zero-size variables) point to different memory addresses, but you cannot rely on this. Dave Cheney wrote more extensively about this, and related behaviors of empty structs, if you're interested: dave.cheney.net/2014/03/25/the-empty-struct
The awkward wait killed me 🤣
Would there be something preventing us from using a pointer to empty struct as key?
Good question. And yes, there is a reason not to use a pointer to the empty struct: They're all identical! So this would actually make the problem worse, not better.
See it in the playground: go.dev/play/p/8OoLFRu3NnM
@boldlygo thank you for that info. Is this behaviour documented somewhere? Can't find it in the spec at first glance.
And another thing - would pointers to the empty structs of different types work? - watching it in the playground, no.
Very interesting behaviour.
BTW loving your podcast 👌
The relevant sentence in the spec reads "Two distinct zero-size variables may have the same address in memory."
IOW, it's not guaranteed. An implementation may choose to have pointers to two empty structs (or other zero-size variables) point to different memory addresses, but you cannot rely on this.
Dave Cheney wrote more extensively about this, and related behaviors of empty structs, if you're interested: dave.cheney.net/2014/03/25/the-empty-struct
Many thanks for clarification@@boldlygo