在Go中增加一个指针 [英] incrementing a pointer in Go
问题描述
安全性。如果没有指针算术,可以创建一种永远不会导致错误地成功的非法地址的语言。编译器和硬件技术已经发展到使用数组索引的循环可以像使用指针运算的循环一样高效。另外,缺少指针算术可以简化垃圾回收器的实现。
所以答案是否定的,你不能增加一个指向Go的指针。
could anyone tell me how to increment a pointer through a string in Go? I've tried ptr += 1, like in C, but it says that the types *string and int are incompatible. Thanks
Go FAQ: Why is there no pointer arithmetic?
Safety. Without pointer arithmetic it's possible to create a language that can never derive an illegal address that succeeds incorrectly. Compiler and hardware technology have advanced to the point where a loop using array indices can be as efficient as a loop using pointer arithmetic. Also, the lack of pointer arithmetic can simplify the implementation of the garbage collector.
So the answer is no, you can't increment a pointer in Go.
这篇关于在Go中增加一个指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!