Best practice to use extern struct or extern pointer to struct?
c, extern, pointers, struct
Solution
If I understand correctly and your "a struct" is supposed to be a global object (which is a questionable design choice), then I'd do it like this:
foo.h:
typedef struct foo_struct
{
/* ... */
} foo;
extern foo the_foo;
foo.c: [If you like and if it makes sense, you can merge this into file1.c.]
#include "foo.h"
foo the_foo = { /* ... */ };
file1.c and file2.c:
#include "foo.h"
#include "global.h"
/* ... */
Problem
Say I have 3 files: file1.c, file2.c and globals.h. file1.c and file2.c both include globals.h. file1.c contains a struct that file2.c needs to use. Is it better to make the struct itself extern or create a pointer to the struct and make that pointer extern in globals.h?