By allowing what you declare, since struct is indeed a class, it provides type safety when creating the C interface.
You can directly declare your structure for your C interface:
struct Foo;
You can declare methods on it
void doStuffThatModifiesFoo( struct Foo * foo, ... ); struct Bar getStuffFromFoo( const struct Foo * foo );
You can also write creation and destruction methods for it.
Below you do not implement Foo as a C structure, but as a class, but your C clients do not need to know this. This is better than passing it as a void *, then throwing it (it is unsafe if someone passes you a void * of a completely different type and you throw it).
Cashcow
source share