Error: incomplete type is not allowed
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?
12 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;