Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Error: incomplete type is not allowed

Writer Matthew Harrington

in .h:

typedef struct token_t TOKEN;

in .c:

#include "token.h"
struct token_t
{ char* start; int length; int type;
};

in main.c:

#include "token.h"
int main ()
{ TOKEN* tokens; // here: ok TOKEN token; // here: Error: incomplete type is not allowed // ...
}

The error I get in that last line:

Error: incomplete type is not allowed

What's wrong?

1

2 Answers

You need to move the definition of the struct into the header file:

/* token.h */
struct token_t
{ char* start; int length; int type;
};
2

In main module there is no definition of the structure. You have to include it in the header, The compiler does not know how much memory to allocate for this definition

TOKEN token;

because the size of the structure is unknown. A type with unknown size is an incomplete type.

For example you could write in the header

typedef struct token_t
{ char* start; int length; int type;
} TOKEN;

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy