Error: incomplete type is not allowed

Fabricio picture Fabricio · Oct 18, 2014 · Viewed 18.5k times · Source

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?

Answer

NPE picture NPE · Oct 18, 2014

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

/* token.h */

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