2

I am a bit comfused about the row of these declarations. I want to make a linked-list for my program but for some reason it keeps putting error when I try to compile it. Basically this will be my main node model and I also have another struct after it (WITHOUT TYPEDEF) for my list. Which compiles just fine. I don't know what's wrong.

I have already tried to put the typedef over the struct student.

typedef struct
{
    char name[50];
    int id;
    node next;

}student;

typedef student* node;

typedef struct listR* list;

struct listR
{
    node head,tail;
    int size;

};

error: unknown type name 'node' warning: initialization make pointer from integer without a cast

Panagiss
  • 3,154
  • 2
  • 20
  • 34

2 Answers2

2

The compiler doesn't know what a node is, because you create the node type after creating the structure.

You can do either :

typedef struct node node;

struct node
{
  char name[50];
  int id;
  node* next;
};

To tell the compiler what a node is,

Or

typedef struct node {
    char name[50];
    int id;
    struct node* next;
} node;
Luc A
  • 98
  • 8
  • Both your ways in some way solved the problem! but I also did that and worked: typedef struct student * node; typedef struct student{ char name[50]; int id; node next; } – Panagiss May 16 '19 at 10:31
  • My solution was generic. Glad it helped. Your last solution (in the comment above) works because you prototype your structure, like in the first example. – Luc A May 16 '19 at 10:31
0

I would use this:

struct Node
{
  struct Node *next;
  struct Node *prev;
};

But then I happen to be one of those who does not like typedeffing structs without a good reason. Read more here: https://stackoverflow.com/a/54752982/6699433

klutt
  • 30,332
  • 17
  • 55
  • 95