|
|
|
|
|
by advocaat23
4355 days ago
|
|
I think it's always weird how multi-dimensional arrays are implemented in most C programming books. Do you guys really use a pointer-pointer approach to represent them? Because nowadays I always allocate a flat array and just calculate the indices. E.g. struct dmatrix {
size_t rows, cols;
double *data;
}
and then a simple double dmatrix_get(struct dmatrix *m, size_t r, size_t c) {
return m->data[r * m->cols + c];
}
is all you need? In particular I find explicit array sizes in function headers very contrived and I have never used them in serious code. Normally it's just a pointer and a length argument similar to e.g. read/write functions in the standard library. |
|