在范围开头声明的指针是“未声明的”

时间:2013-11-28 21:22:19

标签: c

我的编译器和我无法就声明达成一致..

game *copyGame(game *game) {
  game *copy = newGame(game->size);

  copy->size = game->size;

  int x, y;
  for (x = 0; x < game->size; x++)
    for (y = 0; y < game->size; y++)
      copy->board[x][y] = game->board[x][y];

  return copy;
}

编译时

game.c:14:9: error: use of undeclared identifier 'copy'
  game *copy = newGame(game->size);
        ^
game.c:16:3: error: use of undeclared identifier 'copy'
  copy->size = game->size;
  ^
game.c:17:3: error: use of undeclared identifier 'copy'
  copy->board = newBoard(game->size);
  ^
game.c:22:7: error: use of undeclared identifier 'copy'
      copy->board[x][y] = game->board[x][y];
      ^
game.c:24:10: error: use of undeclared identifier 'copy'
  return copy;
当我尝试

时也会发生同样的情况
game *copyGame(game *game) {
  game *copy;
  copy = newGame(game->size);

编译器不抱怨

game *newGame(int size) {
  game *g = (game*) malloc(sizeof(game));

  g->size = size;
  g->board = newBoard(size);

  return g;
}

问题:为什么'复制'未申报?

1 个答案:

答案 0 :(得分:5)

名称捕获。 C对类型和变量使用相同的范围。重命名参数

game *game

其他内容,例如

game *mygame