Prem K Chettri
Prem K Chettri

Reputation: 11

Xcode typedef of struct creating error / warning

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;
}

Upvotes: 0

Views: 184

Answers (1)

Rishikesh Raje
Rishikesh Raje

Reputation: 8614

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

Upvotes: 1

Related Questions