Hi folks,
I understand the use of extern for different type objects, but I'm having trouble using extern on a global structure from one file in another file.
file1.c declares and defines:
struct FREQ{
int a;
char str_freq[MAX_FREQ_STRING_SIZE];
}freq = {0," "};
struct FREQ *p_freq = &freq;
file2.h has:
extern struct FREQ freq;
extern struct FREQ *p_freq;
file2.c has:
freq.a = 1;
If I comment out the line in file2.c above, everything compiles fine.
Without file2.c/.h in the project, I can use this structure in any function in file1.c fine, but if I compile with file2.c/.h in the project, I get a compiler error: unknown size of struct or union .
If I bring the whole structure declaration to file2.h and declare it as extern as follows:
extern struct FREQ{
int a;
char str_freq[MAX_FREQ_STRING_SIZE];
}freq;
I get a compiler error: redefinition tag of struct FREQ
even though it's declared as extern.
I have no problem with external int, char...etc.., but this external structure declaration is giving me fits.
I'm missing something here, can anyone help me?
Thanks alot in advance.