I see that the developers have used opaque types to hide the implementation of the structures from the end users. A typical example is this:
/** Opaque handle type for provider */
typedef void* TSP_provider_t;
This approach however has to disadvantages: 1. The type checking of the compiler is disabled, you can basically put any pointer as an argument to a function taking a TSP_provider_t as an argument
2. Debugging is made more complicated than necessary, when you try to do print *provider in gdb, it says "$20 = (TSP_provider_t) 0x8d52990" instead of
Now you may ask, how do I do this?
As follows: In the public header you make a forward declaration:
typedef struct TSP_otsp_t TSP_provider_t;
In an internal header or in the source code you provide the real struct TSP_otsp_t. You may note that I did not put a * in the type definition above. This is on purpose. If you want to do a prototype as follows:
int tsp_func(const TSP_provider_t *prov, ...); You tell the compiler that tsp_func is not going to touch prov. However if you made a typedef that includes the *, the only thing you can say is that the pointer is const and that we already know.
The problem I currently see as that with the current scheme of opaque types you not only hide the type, but also the type information, and that is not so good.