Re: [go-nuts] why "unsafe.Sizeof(a[0])" doesn't generate panic when a is nil

2020-07-27 Thread Benjamin
Thanks for the response, which makes sense. `unsafe.Sizeof` is indeed a magic package. The parameter of this function isn't evaluated at all, for example, the following code will not generate panic either, because the function test isn't executed at all. func test() int8 { panic("hell")

Re: [go-nuts] why "unsafe.Sizeof(a[0])" doesn't generate panic when a is nil

2020-07-27 Thread 'Axel Wagner' via golang-nuts
`unsafe` is a magic package. It is provided by the language and entirely implemented as compiler-intrinsics - and at compile-time. In particular, the result of `unsafe.Sizeof` must be a compile-time constant . In

[go-nuts] why "unsafe.Sizeof(a[0])" doesn't generate panic when a is nil

2020-07-27 Thread Benjamin
The code is something like below, the a is a nil slice. I am curious why it doesn't generate panic. Could anyone educate me on this? Thanks. var a []int fmt.Println(unsafe.Sizeof(a[0])) -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To