I am getting the following error from this piece of code, I am new to C and learning as I go along!
cc -g -I /usr/lib/i386-linux-gnu -c anld.c
anld.c: In function ‘main’:
anld.c:379:11: error: dereferencing pointer to incomplete type
Main .C file
bridge_t *bridge_p = bridge_new(); //Create / init our bridge
bridge_p->s = server_connect(options.server_p, options.dest_port,
options.ifname_p, options.gateway_p);
bridge .C file
struct bridge
{
int s;
};
bridge_t *bridge_new(void)
{
bridge_t *bridge_p;
bridge_p = OPENSSL_malloc(sizeof *bridge_p);
if (!bridge_p)
{
return NULL;
}
/* Initialise bridge */
memset(bridge_p, '\0', sizeof *bridge_p);
bridge_p->s = -1;
return bridge_p;
}
bridge.h file
typedef struct bridge bridge_t;
Anybody have any ideas??
To avoid the error you mention you should move this:
to
bridge.h
.Currently it is declared local to the module (translation unit)
bridge.c
and so its members are not know to the outside world.Alternativly, if you want to hide the internals of
struct bridge
, you need to add a getter and a setter function to the modulebridge.c
for each member which you want to access from the outside like for example so:bridge.h
bridge.c
So the snippet from your
main.c
would then look like: