0

I'm just trying to pass my struct in recursive function, but in the function when I will pass it again it will be the argument of my struct. I could get the right value but I get the error "passing argument 1 of 'search' from incompatible pointer type [-Wincompatible-pointer-types]gcc "

typedef struct node_t
{
int keyVal;
struct node_t *leftNode;
struct node_t *rightNode;
struct node_t *parent;
}Node;

typedef struct tree_t
{
 struct node_t *root;
}List;



Node *search( List *temp, int value)
    {  
        Node *curr=temp->root;
       if (curr == NULL || curr->keyVal == value)
           return curr;
        if (curr->keyVal < value)


      return search(&(curr->leftNode), value); //here I'm getting a warning
                     ^^^ 
    return search(&(curr->leftNode), value); //the same here 
}                ^^^ 
1
  • 1
    BTW this warning should always be considered as an error. Commented Mar 10, 2022 at 15:16

1 Answer 1

2

Node *search( List *temp, int value) This takes a List aka tree_t as the first argument.

In return search(&(curr->leftNode), value); the curr->leftNode is a Node aka node_t. This is different type and the compiler is correct to complain about incompatible pointer type.

A possible fix would be to change the function signature to Node * search( Node * curr, int value) and remove Node *curr=temp->root;. Do the first call initiating the search as search(x->root, xxx); with your List. The recursive calls would then be correct.

Sign up to request clarification or add additional context in comments.

7 Comments

so we can't fix this warning? or can't we make them as the same type? and thanks for ur answer
What do you want to achieve? The code as it appears in your question is insufficient to determine your intent.
I'm only trying to delete this warning(passing argument 1 of 'search' from incompatible pointer type [-Wincompatible-pointer-types]gcc) the code is working for me but my doctor said that I could fix delete this warning somehow.
It is only working because of unintended consequences.
I was asking about the intent of the code not if you intend to get rid of the warning.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.