Hello everybody.
I have write a program on the linkedlist but when I want to compile its, there are lots of same error. This is errors that I have :
linkedlist.c: In function `add_head':
linkedlist.c:19: warning: initialization from incompatible pointer type
linkedlist.c:20: warning: assignment from incompatible pointer type
linkedlist.c:23: warning: assignment from incompatible pointer type
linkedlist.c:24: warning: assignment from incompatible pointer type
And this is a part of my program :
typedef struct _node{
struct node *prev;
void *data;
struct node *next;
} node;
node* add_head(node *list_node, void* d){
node *n;
node *p=list_node->prev;
p->next=n;
n->prev=list_node->prev;
n->data=d;
n->next=list_node;
list_node->prev=n;
return n;
}
Help me please. It's very important.
Thank's.
pb pointer type
Re:pb pointer type
Code: Select all
typedef struct _node{
struct node *prev;
void *data;
struct node *next;
} node;
anyway, "node" is a typdef and "_node" is a formal struct
so you shoudl be doing this:
Code: Select all
typedef struct _node{
struct _node *prev;
void *data;
struct _node *next;
} node;
Code: Select all
typedef struct _node_entry {
struct _node_entry *prev;
struct _node_entry *next;
} node_entry;
proxy
Re:pb pointer type
typedef struct node{
node *prev;
void *data;
node *next;
} node;
try just that.
But I've no idea what you're code is doing. I mean, the variable n is left uninitialized and never assigned anything for a start. You just declare it, leave it uninitialized, then start trying to write to whatever it points to (n->prev=...). That's going to cause alot of crashes if it ever even manages to compile.
node *prev;
void *data;
node *next;
} node;
try just that.
But I've no idea what you're code is doing. I mean, the variable n is left uninitialized and never assigned anything for a start. You just declare it, leave it uninitialized, then start trying to write to whatever it points to (n->prev=...). That's going to cause alot of crashes if it ever even manages to compile.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:pb pointer type
that won't compile either. The compiler will insist that "node" hasn't been declared prior it is used... I mean, when the internals of "struct node" are declared, the compiler doesn't know a bit about "struct node" itself ... If you tell it to insert a field of type "struct node*", it's okay because the compiler just need to know it's a pointer type and that it refers to a structure called "node" which will be declared later.IRBMe wrote: typedef struct node{
node *prev;
void *data;
node *next;
} node;
try just that.
Code: Select all
typedef struct node {
struct node* prev;
struct node* next;
void *data;
} node;
Code: Select all
typedef struct node node;
struct node {
node* prev;
node* next;
void* data;
};
Code: Select all
struct directory;
struct file;
struct directory {
struct directory* parent;
struct file* files;
whatever;
};
struct file {
struct directory *parent;
whatever;
};