I have several struct: edge, vertex, graph in my library.
I want to hide body of that structs from user (user have to use API), so in header file (eg. edge.h) I’ve just put:
typedef struct edge edge_t;
And definition of edge struct is in edge.c
struct edge {...};
That works fine, but I want don’t want to hide struct’s body from my own code. I want to use in edge.c:
vertex_t v;
v.some_attribute = x;
Now I get dereferencing pointer to incomplete type errors, is it possible to fix that?
Is there any other option that use accessors (like user) for all struct elements?
If you need to use the structure from other source files, they need the complete definition of the structure. So the solution is to put
struct edge { /* ... */ }in the header file as well, and include the header whenever you need to.