-3

I am trying to type cast between a slice of []int32 to a slice of []int64 in Go. Is there anyway i can convert between these types if not directly?

nikhil0929
  • 31
  • 4

1 Answers1

-2

No it is not possible. The reason is that cells of the arrays backing those slices are made of either 4 or 8 bytes. Looking at 4 bytes as if it were 8 makes no sense. You need to copy the contents one by one.

Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
  • That's why you can't assert one to the other, but has nothing to do with why you can't convert one to the other (otherwise the same would be true of int32 <-> int64, which you can convert between, and which also have different widths). – Adrian Nov 07 '19 at 21:15