I’m trying to hide the implementation of my struct. The definitions of the struct are located in Board.h:
typedef struct Board* BoardP;
typedef const struct Board* ConstBoardP;
And i want to allocate memory as needed in Board.c:
#include <stdio.h>
#include <stdlib.h>
#include "Board.h"
#define TARGET_LENGTH 5
#define DEFAULT_BOARD_SIZE 10
struct Board*
newBoard(int r, int c)
{
struct Board *b = (struct Board*) malloc(sizeof(struct Board));
char ** array;
int i;
array = (char**) malloc( r*sizeof(char*) );
for (i=0; i<r; i++)
{
array[i] = malloc( c*sizeof(char) );
}
b->_values = array;
b->_last_player = 'X';
b->_size_r = r;
b->_size_c = c;
return b;
}
But i’m getting the error:
invalid application of ‘sizeof’ to incomplete type ‘struct Board’

I’m running in circles for hours now and need someone to clear my head of the mess i’ve created. If i want to dynamically allocate memory to an array inside a struct how can i define the struct beforehand?
You have to define the
Boardstructure inBoard.cfirst:Or somewhere else that is
#include‘d inBoard.c, anyway, the compiler needs to see its definition to determine its size when usingsizeof()and to access its members. There’s an example in the Wikipedia Page too.