Misleading message

I accidentally wrote foo ((struct Node* ) head);insteadfoo ((Node* ) head);

And I got a message from the 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, should it not be in the first case Node *either struct NODE *?

what does this message mean? Can anyone clarify this?

I can reproduce it here after deliberately entering an error.

Compiler: gcc (GCC) 4.8.1

+4
source share
1 answer

This is a bug in GCC . You are right that the "expected" should be either struct NODE *or Node *. For what it's worth, clang gives the best 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.
+3
source

All Articles