Home Ask Login Register

Developers Planet

Your answer is one click away!

InQusitive February 2016

What does the warning - expected ‘struct node **’ but argument is of type ‘struct node **’ mean?

My code for tree creation from array:

typedef struct
    struct node* left;
    struct node* right;
    int val;

void create_tree(node** root,int val)

    if(*root == NULL )
        *root = (node*)malloc(sizeof(node));
        (*root)->val = val;
        (*root)->left = NULL;
        (*root)->right = NULL;
    if((*root)->val <= val )

    return ;    

int main()
    node *root = (node*)malloc(sizeof(node));
    root->val = 10;
    root->left = NULL;
    root->right = NULL;
    int val[] = { 11,16,6,20,19,8,14,4,0,1,15,18,3,13,9,21,5,17,2,7,12};
    int i;
    return 0;

warning I am getting:

tree.c:10:6: note: expected ‘struct node **’ but argument is of type ‘struct node **’
 void create_tree(node** root,int val)

I am not able to understand what does this warning say? Both expected and actual are of type struct node **. Is it a bug?


Olaf February 2016

After the edit (that's why we ask for a [mcve]), it is clear what the problem is.

Inside your struct, you reference a struct node. But you do not define that type, you only define the alias node for a struct which has no name by itself.

Note that in C struct node resides in a different namespace than "normal" names like variables or typedefed aliases.

So you have to add a tag:

typedef struct node {
    struct node* left;
    struct node* right;
    int val;
} node;

That way you have a struct node as well as a type with name node.

Post Status

Asked in February 2016
Viewed 2,163 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life