Thanks, But I want them hold same data addrs. So I just changed your code to follows: a := [3]int{1, 2, 3} b := (&a)[:]
On Friday, November 11, 2016 at 1:55:06 PM UTC+8, kortschak wrote: > > They have different layouts in memory. Do you just want to do this: > > package main > > import ( > "fmt" > ) > > func main() { > a := [3]int{1, 2, 3} > b := a[:] > fmt.Println(b) > } > > https://play.golang.org/p/OBY7g3azBE > > If so, there's no need for unsafe. If not, what are you trying to do? > > On Thu, 2016-11-10 at 21:50 -0800, steve tang wrote: > > Hi theres, > > > > I used unsafe.Pointer to conv Type [3]int to Type []int, But it > > throws > > a runtime error, Could anybody tell me why? many thanks. The test > > code is > > as follows: > > > > package main > > > > import ( > > "fmt" > > "unsafe" > > ) > > > > func main() { > > a := [3]int{1, 2, 3} > > b := *(*[]int)(unsafe.Pointer(&a)) > > fmt.Println(b) > > } > > > > -- 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. For more options, visit https://groups.google.com/d/optout.