dear all, i defind a struct in a head file and other file will be use this struct , i use keyword extern but always has warning or error message , please tell me really method. thanks a lot.
main.c ---------------- typedef union{ unsigned char Byte; struct{ unsigned _40:1; //Cmd 0 unsigned _41:1; //Acmd 41 unsigned _50:1; //Cmd 16 unsigned _49:1; //Cmd 9 unsigned b4:1; unsigned b5:1; unsigned b6:1; unsigned b7:1; }Audio; struct{ unsigned _51:1; //Cmd 17 read_single_block unsigned _58:1; //Cmd 24 write_single_block unsigned xx1:1; //Cmd 16 unsigned xx2:1; //Cmd 9 unsigned xb4:1; unsigned xb5:1; unsigned xb6:1; unsigned xb7:1; }Bits; }_Data; _Data init_flag; other.c ---------------------------------- extern struct _Data init_flag;
You must have the structure description in a header file, not in main.c.
other.c can not make use of the variable init_flag if it doesn't know the description of the _Data data type.
my_header.h ----- typedef union { ... } _Data;
extern _Data init_flag;
main.c ----- #include "my_header.h"
other.c ----- #include "my_header.h"