I have two c files, foo.c with the functionality and test_foo.c which test the functions of foo.c.
Is there a way to access the struct typedef BAR I defined in foo.c in test_foo.c without using a header file? So far, I was able to avoid a h file so that the whole program would consist of foo.c. Thanks.
foo.c
typedef struct BAR_{...} bar;
BAR *bar_new(...) {..}
test_foo.c
extern BAR *bar_new(...)
error: expected declaration specifiers or ‘...’ before ‘BAR’
The answer is that there is one, and you should use an header file instead.
You can copy the definition of the struct
typedef struct BAR_{...} bar;intotest_foo.cand it will work. But this causes duplication.Every solution that works must make the implementation of struct available to the compiler in
test_foo.c.You may also use an ADT if this suits you in this case.