P0W
P0W

Reputation: 47824

Misleading message

I accidentally wrote foo ((struct Node* ) head); instead of foo ((Node* ) head);

And I got a message from compiler

expected 'struct Node *' but argument is of type 'struct Node *'

#include <stdio.h>
typedef struct NODE
{ 
  char data; 
  struct NODE *next;
} Node;

void foo (Node *head){}

void bar (void *head)
{
 // note: 
  foo ((struct Node* ) head); 
}

int main(){

return 0;
}

This is misleading, shouldn't it be either Node * or struct NODE * in the first case ?

What does this message mean ? Can anybody clarify it ?

I'm able to reproduce it here too after intentionally putting an error.

Compiler :gcc (GCC) 4.8.1

Upvotes: 4

Views: 134

Answers (1)

Carl Norum
Carl Norum

Reputation: 225042

It's a bug in GCC. You're right that the 'expected' should be either struct NODE * or Node *. For what it's worth, clang gives a better message:

example.c:13:8: warning: incompatible pointer types passing 'struct Node *' to
      parameter of type 'Node *' (aka 'struct NODE *')
      [-Wincompatible-pointer-types]
  foo ((struct Node* ) head); 
       ^~~~~~~~~~~~~~~~~~~~
example.c:8:17: note: passing argument to parameter 'head' here
void foo (Node *head){}
                ^
1 warning generated.

Upvotes: 2

Related Questions