Thread: Return from incompatible pointer type

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    5

    Return from incompatible pointer type

    I have a struct:

    Code:
    typedef int DATA;
    typedef struct node {
    struct node *next;
    DATA digit; 
    } NODE;
    
    typedef struct {
    struct node *head; 
    int size; // number of elements in the list 
    } LIST_HEAD;

    I write reverseList fuction to reverses the order of the elements in the list, return a pointer to head of the reversed list.
    Everything seem works fine, but I get the [Warning] return from incompatible pointer type at the return line. Please help to indicate my problem in this code. Thank you.


    Code:
    LIST_HEAD *reverseList(LIST_HEAD *list)	
       NODE  *p,*q,*r;
    	p=list->head;
    	q=NULL;
    
    	while(p!=NULL)
    	{
    	    r=q;
    	    q=p;
    	    p=p->next;
    	    q->next=r;
    	}
    	p = q;
    	list->head=p;
    	return p; //error here
    }
    Last edited by aladin; 03-22-2009 at 08:51 AM.

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    You are returning *p, a pointer to a NODE. The way your function is declared, it wants to return a pointer to a LIST_HEAD. Typically your head node is not a different struct than regular nodes, and will contain data.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    5
    Thanks for quick reply. So I realize that I should return list . I'll try it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM