In my C-project there are some entities. For every entity there are header file and a source file. In the header file I define couple of structs.
For example, let's say our entity is Baz
. Then we have baz.h
and baz.c
. Inside baz.h
there will be something like:
typedef struct baz_t {
int i;
char c;
} Baz;
typedef struct bazbaz_t {
Baz *b;
} BazBaz;
In the same way, I may define an entity Foo
which it's struct contain a pointer to another struct. Something like:
typedef struct foo_t {
Baz *b;
} Foo;
So in conclusion, every entity can have several structs and a struct can have a pointer to another struct in the same entity or a pointer to a struct from another entity.
Finally, those structs (obviously) should be used by other files in the project.
I've created a main.h\ main.c
which #include
s all the entities and each entity have an include to main.h
. I've also added include-guards in order to avoid circular dependency.
Problem is:
I get all those C2016 errors; I've tried to move the typedef
s to main.h
but problem haven't been solved.
How do I solve this problem? I am more then certain there's a right paradigm to handle this kind of situation, but I'm relatively new with C.
You are using a your newly created typename
Baz
as a name here:it is sort of the same as doing:
which is also illegal, because ìnt` is a typename. If you change it to:
it should work.