Thread: dereferencing pointer to incomplete type

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    6

    dereferencing pointer to incomplete type

    Hello, I am making an application that implements doubly linked lists (each node has a pointer to the previous node and the next node), and I am am having trouble with the functions that service the list. I am getting a compiler error "dereferencing pointer to incomplete type", and I am unsure of how to proceed.

    Here is the relevant code

    In list.h

    Code:
     /* linked list node */
    typedef struct _lnode {
    
      struct lnode *prev;
    
      struct lnode *next;
    
      int data;
    
    } lnode;
    
    /* struct for list, contains a pointer to the head of the list */
    typedef struct _llist {
    
      lnode *head;
    
    } llist;
    in list.c
    Code:
    /* adds a node to the front of the list given a pointer to the list and the node to add
    * replaces current head.
    */
    
    void add_front(llist* list, lnode* node) {
      /* new head needs to point to old head as its next.
       * new head needs to point to old tail as its prev.
       * old head needs to point to new head as its prev.
       * tail needs to point to new head as its next.
       * list needs to recognize new head as head.
       */
      
      node->next = (struct lnode *) list->head; 
      node->prev = list->head->prev;
      //ERROR OCCURS NEXT LINE
      list->head->prev->next = node;
      list->head->prev = (struct lnode *)node;
      list->head = node;
     
    }
    list.h is included, so the compiler can find everything okay, so I don't know what 'incomplete type'
    is referring to. On a side note, if I change
    Code:
    typedef struct _llist {
    
      lnode *head;
    
    } llist;
    to
    Code:
    typedef struct _llist {
    
      struct lnode *head;
    
    } llist;
    I will get a lot of the same error on different statements in the add_front function. I am not sure why this happens either. Is there something fundamental about pointers/structs that I am not getting? Thanks in advance.
    Last edited by kataya; 04-16-2008 at 01:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. dereferencing void pointer
    By nkhambal in forum C Programming
    Replies: 4
    Last Post: 04-25-2005, 02:47 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM