Go: using a pointer to array
下面的不是指针指向数组,而是指针指向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的更多相关文章
- 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 ...
- C lang:Pointer and Array
Xx_Introduction Point and Array germane. Xx_Code #include<stdio.h> #define SIZE 4 int main(voi ...
- 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 ...
- initial pointer [expert c]
initial differece between pointer and array Both arrays and pointers can be initialized with a liter ...
- extension Array where Element 代码学习
var fieldNames: [String] { let p = UnsafePointer<Int32>(self.pointer) return Array(utf8Strings ...
- 【译】Rust中的array、vector和slice
原文链接:https://hashrust.com/blog/arrays-vectors-and-slices-in-rust/ 原文标题:Arrays, vectors and slices in ...
- CSharpGL(36)通用的非托管数组排序方法
CSharpGL(36)通用的非托管数组排序方法 如果OpenGL要渲染半透明物体,一个方法是根据顶点到窗口的距离排序,按照从远到近的顺序依次渲染.所以本篇介绍对 UnmanagedArray< ...
- MMORPG大型游戏设计与开发(服务器 游戏场景 事件)
今天第星期天,知识是永远是学习不完的,所以今天这部分算比较轻松,同时也希望大家会有一个好的周末.场景事件即场景的回调,和别的事件一样是在特定的条件下产生的,前面也介绍过场景的各种事件,今天详细的说一说 ...
- 《征服 C 指针》摘录6:解读 C 的声明
一.混乱的声明——如何自然地理解 C 的声明? 通常,C 的声明 int hoge; 这样,使用“类型 变量名;”的形式进行书写. 可是,像“指向 int 的指针”类型的变量,却要像下面这样进行声明: ...
随机推荐
- 【NOIP 2016 总结】
距离杯赛已经很久了,然而我现在才打总结.. 我好惨的说..两场才380... DAY 1 第一题 toy 送分题,模拟的时候+一下再mod一下就好. [当时打完这题就没再看一眼了,好方的说] #inc ...
- 命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?)
解放方法 右键打开这个项目引用System.Web.Mvc,如图: 将复制本地的值改为True,英文的话应该是Copy Local,这样就解决了上面的报错问题.
- CSRF攻击[转]
一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSR ...
- Move to Another Changelist
Move to Another Changelist 将选中的文件转移到其他的 Change list 中. Change list 是一个重要的概念,这里需要进行重点说明.很多时候,我们开发一个项目 ...
- Vim Gtags插件
01.Gtags func:查看定义处 02.Gtags -r func:查看引用处 03.Gtags -s text:查看未被数据库定义的tags 04.copen:打开quick fix显示窗口 ...
- 【POJ】3294 Life Forms
后缀数组. /* 3294 */ #include <iostream> #include <sstream> #include <string> #include ...
- [转] Windows下使用Python读取Excel表格数据
http://www.python-excel.org/这个网站罗列了很多关于在Python下操作Excel文件的信息,这里选择了其介绍的第一个模块xlrd . xlrd 0.9.2版本跨平台同时支持 ...
- 生产环境上shell的解读
一直以来对shell都不是很熟悉,只停留在基本的linux上操作上,这周因为定位问题接触到了生产环境上的脚本,因此作为引子学习一下.很多命令只是点到,等真正需要独立完成的时候再去学习. #!/bin/ ...
- 【jQuery】
TryjQuery:jQuery官方推出的教学视频http://blog.jobbole.com/37699/ jQuery 1.11 / 2.1 beta 版发布,全面支持异步模块加载 √http ...
- ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
于ASP.NET MVC Preview5. 前一篇中我们已经了解了Action Filter 与 内置的Filter实现,现在我们就来写一个实例.就写一个防盗链的Filter吧. 首先继承自Filt ...