I have declared a typedef struct on header files as follows:
myheader.h
typedef struct mystruct mystruct;
myheader.c
typedef struct mystruct{
double *ptr1;
double *ptr2;
int *ptr3;
mystruct *ptr4;
mystruct *ptr5;
}mystruct;
program.c
#include "myheader.h"
int main()
{
mystruct *A = (mystruct *)malloc(sizeof(mystruct));
}
when i try to compile using:
gcc -o myprogram myprogram.c myheader.c
i get the following error:
error: invalid application of ‘sizeof’ to incomplete type ‘mystruct’ {aka ‘struct mystruct’}
mystruct * A = (mystruct *)malloc(sizeof(mystruct));
Is there something wrong with my code or am I compiling in the wrong way?