Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22118

Struct declared in C header file - gcc malloc error

$
0
0

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?


Viewing all articles
Browse latest Browse all 22118

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>