The following is not a pointer pointing to an array, but a pointer pointing to slice
I'm having a little play with Google's go language, and I 've run into something which is fairly basic in C but doesn' t seem to be covered in the documentation I 've seen so far.
When I pass a pointer to an array to a function, I presumed we 'd have some way to access it as follows:
func conv(x []int, xlen int, h []int, hlen int, y *[]int) for i := 0; i<xlen; i++ { for j := 0; j
But the go compiler doesn't like this:
[email protected]:~/dev$ 8g broke.gobroke.go:8: invalid operation: y[i + j] (index of type *[]int)
Fair enough-it was just a guess. I have got a fairly straightforward workaround:
func conv(x []int, xlen int, h []int, hlen int, y_ *[]int) { y := *y_ for i := 0; i<xlen; i++ { for j := 0; j
But surely there's a better way. the annoying thing is that googling for info on go isn't very useful as all sorts of C \ c ++ \ unrelated results appear for most search terms.
The following is a solution:
The semicolon and the asterisk are added and removed.
*y[i+j] += x[i]*h[j]-->(*y)[i+j] += x[i] * h[j];
Go: using a pointer to array