warning: assignment from incompatible pointer type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    warning: assignment from incompatible pointer type

    I have the following code
    Code:
    typedef struct _DoublyLinkedNode {
        int value;
        struct _DoublyLinkedNode *next;
        struct _DoublyLinkedNode *prev;
    }DoublyLinkedNode;
    
    typedef struct DoublyLinkedList {
        int size;
        struct DoublyLinkedNode *firstnode;
        struct DoublyLinkedNode *lastnode;
    }list;
    
    
    list *p;
    
    int main(){
        p = (list*)malloc(sizeof(list));
        DoublyLinkedNode *node;
        node = (DoublyLinkedNode*)malloc(sizeof(DoublyLinkedNode));
        node->value = 7;
        node->next = NULL;
        node->prev = NULL;
        /*
        The other code belongs here.
        */
        return 0;
    }
    When I try to do the following:-
    Code:
    p->firstnode = &node;
    I get the above warning.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    assignment from incompatible pointer type means that you are assigning a value to a pointer variable from a pointer of a different and incompatible type.

    In your code that means that p->firstnode and &node are both pointers but the types are not compatible for assignment. So you probably need to ask and answer the question what are the types of those 2 expressions.

    Comment

    Working...