Error: incomplete type is not allowed

24,141

Solution 1

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

/* token.h */

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

Solution 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;
Share:
24,141
Fabricio
Author by

Fabricio

Updated on June 12, 2020

Comments

  • Fabricio
    Fabricio almost 4 years

    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?