Hi !
Why is this valid
a := [5]int{}
s := a[:0]
but this isn't
s := [5]int{}[:0]
I also tried this but it doesn't work either
s := ([5]int{})[:0]
? It says "slice of unaddressable value". Isn't a slice a strong reference, which would make the value addressable?

Follow

golang.org/ref/spec#Slice_expr
Here it says "Slice expressions construct a substring or slice from a string, array, pointer to array, or slice"

Interestingly, the following _does_ work!
b := (&[5]int{})[:]

· · Mastodon Twitter Crossposter · 0 · 0 · 0
Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!