Reputation: 3468
I'm not really familiar with C and when I was trying to use C to build a linked list, I ran into a little problem and would like to have someone clarify it for me.
Here's my code so far:
typedef struct {
struct dlinkNode_t *next;
struct dlinkNode_t *prev;
void *value;
} dlinkNode_t;
dlinkNode_t* getNext(dlinkNode_t *ptr){
/**return the next node of the node pointed by ptr. Return NULL if next element*/
return ptr->next;
When I tried to compile it I got the following warning:
"warning: return from incompatible pointer type"
I defined dlinkNode_t to be the type of my linked list's node, and each node has 2 pointers pointing forward and backward. Should I define the return type of getNext to be:
struct dlinkNode_t*
But this seems to violate the purpose of typedef, because I want to define dlinkNode as a new type. Any help would be good.
Thank you!
Upvotes: 0
Views: 424
Reputation: 108101
Change it to
typedef struct dlinkNode_t {
struct dlinkNode_t *next;
struct dlinkNode_t *prev;
void *value;
} dlinkNode_t;
Upvotes: 1
Reputation: 1601
Hope this helps.. struct
must have name when you are using same struct
pointer inside it ....
typedef struct dlinkNode {
struct dlinkNode *next;
struct dlinkNode *prev;
void *value;
} dlinkNode_t;
dlinkNode_t* getNext(dlinkNode_t *ptr){
/**return the next node of the node pointed by ptr. Return NULL if next element*/
return ptr->next;
Upvotes: 3