下面的不是指针指向数组,而是指针指向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. 好看的游戏soul calibur

    http://soulcalibur.fr/index.php?wiki/sophitia/ http://astuce-soluce.playfrance.com/index.php/Soul_Ca ...

  2. Oracl 动态执行表不可访问,本会话的自动统计被禁止

    oracle ---建立SQL窗体 写入 select * from tableA; 弹出错误窗口 : 动态执行表不可访问,本会话的自动统计被禁止.在执行菜单里你可以禁止统计,或在v$session, ...

  3. sqlmap批量扫描burpsuite请求日志记录

    sqlmap可以批量扫描包含有request的日志文件,而request日志文件可以通过burpsuite来获取, 因此通过sqlmap结合burpsuite工具,可以更加高效的对应用程序是否存在SQ ...

  4. 捉虫记2:windows程序句柄泄露的上下文环境

    作为程序员,开发程序是基本功,而调试程序也是必不可少的技能之一.软件在主体功能开发完成后会经历各个阶段的测试,才会被发布.在测试过程中,出现较多的可能就是内存泄漏,句柄泄漏,异常崩溃等属于非功能型的软 ...

  5. Hibernate征途(五)之继承映射和组件映射

    之所以把这两种映射放到一起说,是因为二者都是以复用为目的,减少了代码和配置量,这是相同点:二者之间的不同点类似继承和实现的区别:继承的类是一个事物的抽象,而实现的接口仅仅是功能的抽象. 继承映射 如上 ...

  6. Wince6 RIL层移植

    RIL移植: 因为不同的模组,支持的AT命令有所不同,或是格式不一样,还有就是返回不一样,我们有必要对不同的模组进行RIL驱动移植. 在Response.cpp,Msg.cpp等 文件中ParseXX ...

  7. Pomelo服务器琐碎方法

    1.获取客户端ip地址:session__session__.__socket__remoteAddress.ip 2.日志文件无法打印到文件,删除node_modules/pomelo/node_m ...

  8. php类的实现

    zend_class_entry typedef struct _zend_class_entry zend_class_entry; struct _zend_class_entry { char ...

  9. BZOJ_1022_[SHOI2008]_小约翰的游戏John_(博弈论_反Nim游戏)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1022 反Nim游戏裸题.详见论文<组合游戏略述——浅谈SG游戏的若干拓展及变形>. ...

  10. [LOJ 1038] Race to 1 Again

    C - Race to 1 Again Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu D ...