Invalid application of sizeof to incomplete type with a struct Invalid application of sizeof to incomplete type with a struct c c

Invalid application of sizeof to incomplete type with a struct


It means the file containing main doesn't have access to the player structure definition (i.e. doesn't know what it looks like).

Try including it in header.h or make a constructor-like function that allocates it if it's to be an opaque object.

EDIT

If your goal is to hide the implementation of the structure, do this in a C file that has access to the struct:

struct player *init_player(...){    struct player *p = calloc(1, sizeof *p);    /* ... */    return p;}

However if the implementation shouldn't be hidden - i.e. main should legally say p->canPlay = 1 it would be better to put the definition of the structure in header.h.


The cause of errors such as "Invalid application of sizeof to incomplete type with a struct ... " is always lack of an include statement. Try to find the right library to include.


Your error is also shown when trying to access the sizeof() of an non-initialized extern array:

extern int a[];sizeof(a);>> error: invalid application of 'sizeof' to incomplete type 'int[]'

Note that you would get an array size missing error without the extern keyword.