Question

I am working with a C89 compiler and I'm coming across some pointer typing error.

Calling code:

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

Print_out_cpu is defined elsewhere and the H file is #included in.

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

I get error:

error: incompatible type for argument 1 of 'print_out_cpu'

As best as I can understand,&cpu_state returns type cpu_state_type*, so I am confused.

Was it helpful?

Solution

Are you sure the prototype has the * in it? If I compile (gcc -std=c89) the following code, I get that exact error:

  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);
  }

OTHER TIPS

I don't see any problems, so I wonder if it's an error in your include statement or in the file, etc.

It'll be difficult to determine the cause of the error without seeing more of the source. Try creating a source file like:

#include struct cpu_state_type cpu_state;

void foo() {
print_out_cpu(&cpu_state); }

If that doesn't trigger the problem, keep adding things until it does. If it does trigger the problem, extract the pertinent parts of the header file into your source (and remove the #include) and try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top