B
Ben
Hi,
I am having trouble debugging a segmentation fault...here's my data structure:
typedef struct CELL *pCELL; /* Pointers to cells */
struct CELL {
SYMBOL symbol;
pCELL prev_in_block;
pCELL next_in_block;
pCELL prev_in_column;
pCELL next_in_column;
pCELL prev_in_row;
pCELL next_in_row;
};
pCELL mArray[MAX2][MAX][MAX][MAX2]; /* The multi-dimensional array */
So, mArray is an array of pointers to CELLs. And each CELL contains a symbol and pointers to the neighbouring CELLs. I am
representing a 4d "grid" here, but you can think of it like a 2d one.
Note the boundary CELLS should not point to anything, e.g. the first piece in a row should have a prev_in_block value of NULL,
meaning the address of the CELL it points to is NULL, meaning there's no such CELL.
Ok, my problem comes when trying to ACCESS symbols via the pointers, e.g. printing out the symbol in a "square" in the grid and
all of it's surrounding symbols. Then I get an intermittent seg fault. This first line is always ok:
value = mArray[bb][cc][rr][vv]->symbol;
But one or more of the following will cause a seg fault:
pib = mArray[bb][cc][rr][vv]->prev_in_block->symbol;
nib = mArray[bb][cc][rr][vv]->next_in_block->symbol;
pic = mArray[bb][cc][rr][vv]->prev_in_column->symbol;
nic = mArray[bb][cc][rr][vv]->next_in_column->symbol;
pir = mArray[bb][cc][rr][vv]->prev_in_row->symbol;
nir = mArray[bb][cc][rr][vv]->next_in_row->symbol;
I can't find a particular pattern with this, different "squares" (changing bb,cc etc) crash it at different lines - it seems to
be no relation to which squares have a NULL pointer for example.
But, some of the statements above work correctly some of the time...leading me to believe I have the syntax correct. So what
could be the issue? If there's any other information needed happy to provide.
cheers,
Ben
I am having trouble debugging a segmentation fault...here's my data structure:
typedef struct CELL *pCELL; /* Pointers to cells */
struct CELL {
SYMBOL symbol;
pCELL prev_in_block;
pCELL next_in_block;
pCELL prev_in_column;
pCELL next_in_column;
pCELL prev_in_row;
pCELL next_in_row;
};
pCELL mArray[MAX2][MAX][MAX][MAX2]; /* The multi-dimensional array */
So, mArray is an array of pointers to CELLs. And each CELL contains a symbol and pointers to the neighbouring CELLs. I am
representing a 4d "grid" here, but you can think of it like a 2d one.
Note the boundary CELLS should not point to anything, e.g. the first piece in a row should have a prev_in_block value of NULL,
meaning the address of the CELL it points to is NULL, meaning there's no such CELL.
Ok, my problem comes when trying to ACCESS symbols via the pointers, e.g. printing out the symbol in a "square" in the grid and
all of it's surrounding symbols. Then I get an intermittent seg fault. This first line is always ok:
value = mArray[bb][cc][rr][vv]->symbol;
But one or more of the following will cause a seg fault:
pib = mArray[bb][cc][rr][vv]->prev_in_block->symbol;
nib = mArray[bb][cc][rr][vv]->next_in_block->symbol;
pic = mArray[bb][cc][rr][vv]->prev_in_column->symbol;
nic = mArray[bb][cc][rr][vv]->next_in_column->symbol;
pir = mArray[bb][cc][rr][vv]->prev_in_row->symbol;
nir = mArray[bb][cc][rr][vv]->next_in_row->symbol;
I can't find a particular pattern with this, different "squares" (changing bb,cc etc) crash it at different lines - it seems to
be no relation to which squares have a NULL pointer for example.
But, some of the statements above work correctly some of the time...leading me to believe I have the syntax correct. So what
could be the issue? If there's any other information needed happy to provide.
cheers,
Ben