Re: [go-nuts] Re: unsafe.Pointer to byte slice

2017-07-09 Thread Santhosh Ram Manohar
On Sun, Jul 9, 2017 at 12:30 AM, Dave Cheney wrote: > As your using the unsafe package your doing things which are not > considered safe by the lanaguge so only imprecise interpretations are > possible. My interpretation is, assuming that next words after p in memory > are zeroed the you have eff

[go-nuts] Re: unsafe.Pointer to byte slice

2017-07-09 Thread T L
On Sunday, July 9, 2017 at 6:31:24 AM UTC+8, Santhosh Ram Manohar wrote: > > hello, > > This piece of code prints [10 0 0 0] as expected.. > > func main() { > i := 10 > p := unsafe.Pointer(&i) > intPtr := (*[4]byte)(p) > fmt.Println(*intPtr) > } > > But if I conver

Re: [go-nuts] Re: unsafe.Pointer to byte slice

2017-07-09 Thread Dave Cheney
As your using the unsafe package your doing things which are not considered safe by the lanaguge so only imprecise interpretations are possible. My interpretation is, assuming that next words after p in memory are zeroed the you have effectively a slice that points to a backing array at *p, and

Re: [go-nuts] Re: unsafe.Pointer to byte slice

2017-07-08 Thread Santhosh Ram Manohar
On Sat, Jul 8, 2017 at 7:37 PM, Ian Lance Taylor wrote: > On Sat, Jul 8, 2017 at 6:59 PM, Santhosh Ram Manohar > wrote: > > > > On Saturday, July 8, 2017 at 4:09:32 PM UTC-7, Dave Cheney wrote: > >> > >> An array is a vector of values in memory. A slice is a small struct that > >> describes an a

Re: [go-nuts] Re: unsafe.Pointer to byte slice

2017-07-08 Thread Ian Lance Taylor
On Sat, Jul 8, 2017 at 6:59 PM, Santhosh Ram Manohar wrote: > > On Saturday, July 8, 2017 at 4:09:32 PM UTC-7, Dave Cheney wrote: >> >> An array is a vector of values in memory. A slice is a small struct that >> describes an array stored elsewhere in memory. > > > I understand the slice vs array d

[go-nuts] Re: unsafe.Pointer to byte slice

2017-07-08 Thread Santhosh Ram Manohar
Dave, On Saturday, July 8, 2017 at 4:09:32 PM UTC-7, Dave Cheney wrote: > An array is a vector of values in memory. A slice is a small struct that > describes an array stored elsewhere in memory. I understand the slice vs array difference. But in this statement, intPtr := (*[]byte)(p) my int