Because of how you’ve ordered your includes, the compiler sees void some_func(my_structure *x);
before it sees typedef struct abcd { int a; } my_structure;
.
Let’s walk this through.
Assuming my_struct.h
is processed first, we get the following sequence of events:
UTILSH
is definedMAINH
is defined- Because
UTILSH
is already defined, we don’t processmy_struct.h
again, so the typedef isn’t processed void some_func(my_structure *x);
is processed.- Now the
typedef
is processed.
So after preprocessing, your compiler sees the following sequence of declarations:
... void some_func(my_structure *x); ... typedef struct abcd {...} my_structure;
Bad juju. You either need a forward declaration of my_structure
in main.h
, or you need to break that circular dependency (which is the much preferred option). Is there anything in main.h
that my_structure.h
actually uses? If so, you will want to factor it out into a separate file that both main.h
and my_structure.h
include.