I am writing a C program and using gcc 4.4.6 to compile. I do not want to use a c++ compiler.
I am implementing a component and I intend to have several instances of this component live and owned by other components at runtime.
As a means of decoupling the definition of an interface from its implementation and hide the internal structures and datatypes it uses in that implementation I looked to use a forward struct declaration.
Interface file: component.h
struct _hidden_implementation_type;
typedef struct _hidden_implementation_type visible_type_to_clients;
int component_function1(visible_type_to_clients instance);
Implementation file: component.c
struct _hidden_implementation_type
{
int foo;
};
Client file: main.c
int main(int argc, char** argv)
{
visible_type_to_clients a;
return component_function1(a);
}
How do I make this work? What other approach is there to allow multiple component instantiation and provide a decoupling between the public interface and implementation otherwise?