On Wed, Oct 11, 2023 at 8:11 PM Torsten Bronger
<[email protected]> wrote:
> Then, all boils down to the fact that you can’t pass []float64 as an
> []any. To be honest, I still don’t fully understand why this is
> forbidden, so I just accept that the language does not allow it.
It's the same reason why one cannot pass, say []byte as an []int. The
backing arrays of the two slices have incompatible memory layouts. To
make it work the compiler would have to inject code like
(schematically)
var tmp []int
for i, v := range byteSlice {
tmp = append(tmp, v)
}
callTheFuntion(tmp)
It is doable but it has a cost which the language designers preferred
not to hide.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CAA40n-Vp%2B22PhXxxYBwvj77G3zFVEStSzr1%3DTsCuALYZS-%2BHQg%40mail.gmail.com.