I have 3 files: main.c
, def.c
, def.h
. Both .c
files include def.h
. All the files are in the same directory. My compiler is gcc version 4.9.2 .
In def.h :
struct _info {
int a;
};
In def.c :
#include "def.h"
struct _info info[] = {};
And in main.c :
#include "def.h"
extern struct _info info[];
When I build def.c
as an object file and then build with main.c
like:
gcc -c def.c
gcc main.c def.o
And I got an error message: array type has incomplete element type
If I use typedef
to define struct _info
as INFO
like:
typedef struct _info INFO;
And replace struct _info
with INFO
in .c
files. Compile ok then.
But why and what does typedef
do?
Thanks for everybody's help. This question end up with a misspelling in main.c
. Something like:
extern struct _infoo info[];
When typedef
replace them, all work fine definitely.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.