package main

 

import "fmt"

import "unsafe"

 

type Age int

 

func main() {

    var ages = []Age{17, 18, 19}

    var ints = *(*[]int)(unsafe.Pointer(&ages))

   fmt.Println(ints)

}

 

From: <golang-nuts@googlegroups.com> on behalf of T L <tapir....@gmail.com>
Date: Friday, August 26, 2016 at 10:11 AM
To: golang-nuts <golang-nuts@googlegroups.com>
Cc: <tapir....@gmail.com>
Subject: Re: [go-nuts] Why can't convert []T to []T2 if T2 is a copy definition 
of T?

 



On Saturday, August 27, 2016 at 12:36:58 AM UTC+8, Axel Wagner wrote:

There is none. It would be perfectly possible and reasonable to make this 
possible, but it probably didn't seem worth the effort to introduce this 
special case into the language which has such a limited use. If you can't live 
without, you can always use unsafe to do it yourself (though, of course, that's 
unsafe).


What effort needs to make to convert []Age into []int? 
 

 

On Fri, Aug 26, 2016 at 6:09 PM, T L <tapi...@gmail.com> wrote:



On Saturday, August 27, 2016 at 12:05:28 AM UTC+8, Jan Mercl wrote:

 

On Fri, Aug 26, 2016, 17:59 T L <tapi...@gmail.com> wrote:

 

 

-- 


why the underlying types of []Age and []int are not the same.

 

The underlying type of an anonymous type []T is []T.

 

 


What are differences between memory layouts of []Age and []int?
 

-- 

-j

-- 
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

-- 
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.

-- 
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.

Reply via email to