I have main in which I used the node struct however defintion of node and it’s manipulation operations are localed in a file in the directory called NODE/
I created NODE/node.h which has:
typedef struct node node;
struct node
{
int my_reg;
node *left;
node *right;
} ;
I created NODE/node.c and include in it node.h which has node_insert node_remove;
However I am using the node struction in school_address.c in which I also include NODE/node.h and NODE/node.c
I tried putting
extern struct node
in school_address.c
Yet the code doesn’t compile and complains of redefinition in node.h
Any idea?
externis for variables, not type definitions. You should just include the header in all modules that need to know aboutstruct node; that is substituted for the entire header’s content, inline.What you should not do is include a C file in another C file. Instead, you should declare the prototypes of the common functions in a header.
E.g.,
becomes, if you put the prototype for
node_insertin the header,after the C preprocessor is done with it, so
struct nodeandnode_insertare visible inmain.