3

我正在使用 C89 编译器,但遇到了一些指针输入错误。

调用代码:

struct cpu_state_type cpu_state;
//Stuff here....
foo()
{
    print_out_cpu(&cpu_state);
}

Print_out_cpu 在别处定义,H 文件包含在其中。

struct cpu_state_type
{
  int r[12];
};
void print_out_cpu(struct cpu_state_type *c);

我得到错误:

error: incompatible type for argument 1 of 'print_out_cpu'

据我所知,&cpu_state返回 type cpu_state_type*,所以我很困惑。

4

2 回答 2

1

你确定原型里面有*吗?如果我编译(gcc -std=c89)以下代码,我会得到确切的错误:

  struct cpu_state_type {
     int r[12];
  };

  // note that it is the structure as the param here (not the pointer)
  void print_out_cpu(struct cpu_state_type c);
  struct cpu_state_type cpu_state;

  foo()
  {
     print_out_cpu(&cpu_state);
  }
于 2010-03-09T21:08:20.773 回答
0

我没有看到任何问题,所以我想知道这是否是您的包含语句或文件中的错误等。

如果不查看更多来源,将很难确定错误的原因。尝试创建一个源文件,如:

#include struct cpu_state_type cpu_state;

无效 foo() {
print_out_cpu(&cpu_state); }

如果这不会触发问题,请继续添加内容,直到它触发。如果确实触发了问题,请将头文件的相关部分提取到您的源中(并删除#include)并重试。

于 2010-03-09T18:55:30.363 回答