下面的不是指针指向数组,而是指针指向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 := ; i<xlen; i++ {
for j := ; j<hlen; j++ {
*y[i+j] += x[i]*h[j]
}
}
}

But the Go compiler doesn't like this:

sean@spray:~/dev$ 8g broke.go
broke.go:: 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 := ; i<xlen; i++ {
for j := ; j<hlen; j++ {
y[i+j] += x[i]*h[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 semicolon and the asterisk are added and removed.

*y[i+j] += x[i]*h[j]
-->
(*y)[i+j] += x[i] * h[j];

最新文章

  1. 手机开发中的AP与BP的概念
  2. iPhone添加邮箱
  3. js基础知识:变量
  4. mysql多实例(个人的情况,不是大众的)里面有配置好的脚本+主从复制
  5. 电梯调度--c++--软件工程
  6. WordPress Platinum SEO插件跨站脚本漏洞
  7. The account is locked
  8. poj 1872 A Dicey Problem WA的代码,望各位指教!!!
  9. Vmware虚拟机安装Ubuntu 16.04 LTS(长期支持)版本+VMware tools安装
  10. jquery按钮倒计时
  11. 准确率(Accuracy), 精确率(Precision), 召回率(Recall)和F1-Measure(对于二分类问题)
  12. 《android开发艺术探索》读书笔记(十四)--JNI和NDK编程
  13. Python基础之函数和模块
  14. vue样式控制的方式
  15. idea代码回退到前面的版本
  16. nginx 目录讲解
  17. nginx 504 Gateway Time-out
  18. VS2013新建web项目时出错,系统找不到指定文件
  19. Luogu4783 【模板】矩阵求逆(高斯消元)
  20. POJ 1830 开关问题(高斯消元)题解

热门文章

  1. linux 修改命令行编码 乱码解决方案
  2. 【转】Picasso – Android系统的图片下载和缓存类库
  3. Android 签名(7)签名常见问题,debug签名和release签名的区别等
  4. 【ZOJ】2112 Dynamic Rankings
  5. Eclipse优化
  6. poj3281
  7. usaco /the second wave
  8. I.MX6 build.prop
  9. Oracle Data Guard
  10. 多线程程序设计学习(8)Thread-Per-Message