敲了我1个小时的脑袋,找不到答案:
int *get_possible_moves(int **board, int *w, int *h, int *x, int *y) {
int movespossible=0;
int moveslist[2][8];
//4
if(x + 1 <= w-1 && y + 2 <= h - 1) {
if(board[*(int *)y + 2][*(int *)x + 1] == 0) {
moveslist[movespossible][0] = *(int *)x + 1;
breakpoint-> moveslist[movespossible][1] = *(int *)y + 2;
movespossible++;
}
}
在标记为断点的行 -> 我的 **board 被取消引用。任何线索为什么会这样?没有并发线程正在使用内存中的这个地方。另外,我根本没有在这一行使用 **board。
//3
if(x + 2 <= w - 1 && y + 1 <= h - 1) {
if(board[*(int *)y + 1][*(int *)x + 2] == 0) {
moveslist[movespossible][0] = *(int *)x + 2;
moveslist[movespossible][1] = *(int *)y + 1;
movespossible++;
}
}
此代码可以完美运行。
提前致谢!
最佳答案
你有:
int moveslist[2][8];
...但您经常引用它:
moveslist[movespossible][0]
moveslist[movespossible][1]
...你不应该这样做吗:
moveslist[0][movespossible]
moveslist[1][movespossible]
?
关于c - 指针矩阵在代码中间被取消引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2146248/