0

Just wondering if I am making some stupid mistake or its Xcode.

I have typedef of a struct and now while comparing the pointer between two variable of same type, creates a incompatible pointer in Xcode but not in linux. Could any one please let me know whats going on here.

typedef struct Node
{
    // treeNode has a hidden Address
    int size;
    struct treeNode *left;
    struct treeNode *right;

} treeNode;

treeNode* FindMin(treeNode *node)
{
    if(node==NULL)
    {
        return node;
    }
    if(node->left) 
        return FindMin(node->left); // Error :- treeNode is incompatible with Node
    else
        return node;
}


// If I type cast it .. Show no sign of error..


treeNode* FindMin(treeNode *node)
{
    if(node==NULL)
    {
        /* There is no element in the tree */
        return node;
    }
    if(node->left) 
        return FindMin((struct Node *)node->left); // No Error here
    else
        return node;
}
1
  • Are you getting a warning from Xcode? Or is it a compiler error? If so, what error did you get and what are your compiler flags? Commented Feb 5, 2016 at 4:49

1 Answer 1

1

Make your declaration of treenode like this

typedef struct treeNode
{...

instead of

typedef struct Node
{...

You are accessing struct treeNode in the declaration struct treeNode *left; below, but are declaring the struct as struct Node

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

Comments

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.