We have an assignment in school where we got a header file and we
need to implement it. The header defines:
typedef struct Board* BoardP;
which to my understanding means the BoardP is a pointer to struct Board.
Anyhow, my implementation is:
typedef struct Board
{
int width;
int height;
char *board;
} *BoardP;
But i keep getting:
Board.c:21: error: redefinition of typedef ‘BoardP’
Board.h:4: note: previous declaration of ‘BoardP’ was here
Any ideas as to why this happens? Thanks!
EDIT: another question. As you can see my struct hold an array of characters. When I write a constructor should I initialize (malloc(sizeof(height*width)) the array first and then the struct? And how about use of free()? Should I free the array first and then the struct?
Thanks
Drop the
typedeffrom the definition.A struct is a struct; it’s not like you always have to
typedefit. To be honest, I onlytypedef structsfor opaque pointers.From
style(9):