data structures - Multiple declaration error in C using DOSBox version 0.74 -
i'm creating simple project on dosbox version 0.74, double linked list. created 3 files:
- a header file dlinkedlist.h contains structure of list node , functions prototypes.
- dlinkedlist.c file. contains implementation of these functions.
- main.c file
the header file included in both of other 2 files. , dlinkedlist.c
included in main.c
, don't dosbox says functions in dlinkedlist.c
aren't defined in main()
. errors solved when included .c
file in main.c
.
now problem error
error dlinkedlist.h multiple declaration of listnode
this code in header file besides prototypes.
typedef struct listnode{ int id; char name[size]; struct listnode *next; struct listnode *prev; }listnode; typedef struct list{ listnode *head; int size; }list;
and dlinkedlist.c included in main.c.
you don't include c files in other c files.
the accepted practice create header file containing declarations (not definitions) , include that.
what's happening you're including header file twice, once in main.c
, again in dlinkedlist.c
included main.c
.
so, example, if dlinkedlist.c
file was:
int getfortytwo (void) { return 42; }
then equivalent dlinkedlist.h
file have prototype:
int getfortytwo (void);
the scenario can think of may think need include c file if you're doing full compilation/linking of main.c
on own, , that's not way it.
you compile main.c
, other c file individual object files, link 2 together.
Comments
Post a Comment