下面的不是指针指向数组,而是指针指向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];

Go: using a pointer to array的更多相关文章

  1. c pointer and array

    Pointer:  A pointer is a variable that contains the address of a variable. if c is a char and p is a ...

  2. C lang:Pointer and Array

    Xx_Introduction Point and Array germane. Xx_Code #include<stdio.h> #define SIZE 4 int main(voi ...

  3. The correct way to initialize a dynamic pointer to a multidimensional array

    From:https://stackoverflow.com/questions/18273370/the-correct-way-to-initialize-a-dynamic-pointer-to ...

  4. initial pointer [expert c]

    initial differece between pointer and array Both arrays and pointers can be initialized with a liter ...

  5. extension Array where Element 代码学习

    var fieldNames: [String] { let p = UnsafePointer<Int32>(self.pointer) return Array(utf8Strings ...

  6. 【译】Rust中的array、vector和slice

    原文链接:https://hashrust.com/blog/arrays-vectors-and-slices-in-rust/ 原文标题:Arrays, vectors and slices in ...

  7. CSharpGL(36)通用的非托管数组排序方法

    CSharpGL(36)通用的非托管数组排序方法 如果OpenGL要渲染半透明物体,一个方法是根据顶点到窗口的距离排序,按照从远到近的顺序依次渲染.所以本篇介绍对 UnmanagedArray< ...

  8. MMORPG大型游戏设计与开发(服务器 游戏场景 事件)

    今天第星期天,知识是永远是学习不完的,所以今天这部分算比较轻松,同时也希望大家会有一个好的周末.场景事件即场景的回调,和别的事件一样是在特定的条件下产生的,前面也介绍过场景的各种事件,今天详细的说一说 ...

  9. 《征服 C 指针》摘录6:解读 C 的声明

    一.混乱的声明——如何自然地理解 C 的声明? 通常,C 的声明 int hoge; 这样,使用“类型 变量名;”的形式进行书写. 可是,像“指向 int 的指针”类型的变量,却要像下面这样进行声明: ...

随机推荐

  1. Java 另一道构造器与构造器重载的题目

    题目: 请写出以下程序的输出结果 public class ConstructorTest2 { public static void main(String[] args) { new B(&quo ...

  2. Oracle导入(imp )与导出(exp )

    导出exp username/password@orcl file=db.dmp 导入imp username/password@orcl file=h:\db.dmp  full=y 备注:在导入之 ...

  3. C语言 结构体的内存对齐问题与位域

    http://blog.csdn.net/xing_hao/article/details/6678048 一.内存对齐 许多计算机系统对基本类型数据在内存中存放的位置有限制,它们会要求这些数据的首地 ...

  4. P163、面试题29:数组中出现次数超过一半的数字

    题目:数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2. 思 ...

  5. Android 签名(1)为什么要签名

    所有的应用程序都必须有数字证书,Android系统不会安装一个没有数字证书的应用程序 签名可以: 1,用特权,2完整性鉴别,3安全保证, 1,专用权限或特权要签名 一些特权要经签名才允许.签名可用:S ...

  6. 【HDOJ】1667 The Rotation Game

    1. 题目描述有个#字型的条带,可以从横线或竖线进行循环移动,求通过各种移动最终使中心的8个字符全等的长度最短并相同长度字典序最小的操作序列.2. 基本思路24个数据,8种移动方式,数据量很小了,所以 ...

  7. 配置oschina for pc 开发环境

    oschina for pc 是一款用python + pyqt + html + css +js开发的桌面程序,感觉十分强大.python开发快捷, 网页技术绚丽,正是桌面程序需要的. 感谢铂金小鸟 ...

  8. node安装插件方法

    node安装插件方法有几种,这里列出常用的两种方法: 方法1: 进入要安装插件的目录,直接用 npm 软件安装包安装,如(安装express): cd /project npm install -g ...

  9. OWIN katana注册中间件的几种写法

    首先特别说明下在startup中注册完中间件的两个注意事项,看到有人写的东西有误导人的作用.关于startup启动发现类的内容,参照这里 http://www.asp.net/aspnet/overv ...

  10. c# 产生随机字符串,包括大小写字母和数字

    #region MyRegion //產生密碼 protected static string GetPwd() { return CreateRandomNum123(2) + CreateRand ...