1

The error appears in the List* next line.

typedef struct {
    List* next;
    int data;
    int index;
} List;
2
  • 4
    Welcome to SO. There is no type List that is known to the compiler. You cannot use a type before it is defined. You need to use the struct tag if you want to use that type during the declaration: typedef struct List { struct List *next; ...} You might revisit your learning material that introduces linked lists. It should explain that topic. Commented Jan 11, 2022 at 7:25
  • This is surely a FAQ. Do we have any post that could be used as canonical dupe? Commented Jan 11, 2022 at 8:00

1 Answer 1

3

As noted in comments, the type List is not known when you use it. There are two solutions to this.

The first is to simply use struct List *next:

typedef struct List {
   int n;
   struct List *next;
} List;

The other is to typedef List into existence before defining struct List.

typedef struct List List;

struct List {
   int n;
   List *next;
};

Which is better is opinion, and thus inappropriate for SO.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.