Got it, but I am not using the struct members in the header, I just
need the type name ...
Typedef names have no linkage. They have little practical use
anyway; the only time a typedef is actually required is in some
relatively obscure corner cases of the va_arg() macro from <stdarg.h>.
Just stop using the typedefs. Write "struct <structure-name>";
then the whole problem goes away:
file1.c:
struct zorg { ... }; /* declares and defines the structure type */
/* code that uses the actual structure */
file2.c:
struct zorg; /* declares the type without defining it */
extern struct zorg *new_zorg(void);
extern void act_on_zorg(struct zorg *);
extern voide destroy_zorg(struct zorg *);
void intermediate_func(struct zorg *p) {
... do some stuff ...
act_on_zorg(p);
... do some more stuff ...
}
void top_level_func(void) {
struct zorg *z;
...
z = new_zorg();
intermediate_func(z);
destroy_zorg(z);
}
Note that file2.c never needs to know what is inside a "struct
zorg", and no typedefs clutter up the cleanliness of using C's
type-defining and type-referring keyword "struct", which clearly
stands for "STRange spelling for User-defined abstraCt Type".
(For English-speakers, just pretend it *is* the word "type" and
it will all make sense. Or:
#define type struct
type zorg;
extern type zorg *new_zorg(void);
See?
)