Use the arr1 style when the length of the C array is known at compile time, and the arr2 style when it’s not known till runtime.
Andy > On Nov 3, 2017, at 9:18 AM, DV <dimiter.velich...@gmail.com> wrote: > > Which "style" of wrapping a C array in a Go slice is more idiomatic in this > code - https://play.golang.org/p/6EbKl22MPQ - "arr1" or "arr2"? They both > seem to produce the exact same result. > > I've seen the "arr2" style more often, but I don't understand why. The way I > wrapped "arr1" seems more clear to me - you have to know the length of the C > array, so why not just declare the pointer to the array with the correct > length to begin with? Why is the 1<<30 bit the more accepted style, e.g. here > - cgo > <https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices>. It > seems a bit noisy, especially with having to remember to put the length *and* > capacity when slicing the array. > > I have a feeling I'm missing something important but I don't understand > what... > > -- > 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 > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <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.