1
我正在嘗試做一個Golang的簡單例子。這個例子是在golang之旅的36頁裏。 這是我的代碼:Golang指數超出範圍
package main
import "code.google.com/p/go-tour/pic"
import "fmt"
func Pic(dx, dy int) [][]uint8 {
dx8 := uint8(dx)
s1 := make ([][] uint8, dy)
fmt.Printf("%d\n", len(s1), cap(s1))
for i := range s1{
fmt.Printf("%d\n",i)
for j := range s1 {
fmt.Printf("%d\n",j)
s1[i][j] = dx8
}
}
return s1
}
func main() {
pic.Show(Pic)
}
而且我得到了錯誤:
256
%!(EXTRA int=256)0
0
panic: runtime error: index out of range
goroutine 1 [running]:
panic(0x18b820, 0x1040a010)
/usr/local/go/src/runtime/panic.go:464 +0x700
main.Pic(0x100, 0x100, 0x0, 0x0, 0x0, 0x0)
/tmp/sandbox716191956/main.go:17 +0x4e0
code.google.com/p/go-tour/pic.Show(0x1d7988, 0x104000e0)
/go/src/code.google.com/p/go-tour/pic/pic.go:20 +0x60
main.main()
/tmp/sandbox716191956/main.go:26 +0x20
Program exited.
我只是想返回Show
功能使用bidimensial片。