Originally Posted by
Dave Evans
It isn't my example; I was just correcting the (typographical) syntax error from the previous post.
In fact, in my experience, functions that deal with 2-D matrices almost always use pointers or pointers-to-pointers except for very specialized applications that have fixed-size matrices.
Even fixed-size matrix functions (3x3 graphics manipulations, for example) might be more efficient with pointers, since element access is just a couple of indirect address operations instead of using the 2-D matrix calculations involving an addition and a multiplication.
D.
It may be worthwhile to pass a 2d stack by creating pointers to each row, and passing that as an array. that would mean doing something like this:
Code:
void func(int **array); //same as int *array[]
...
int main(){
int array2d[3][10];
int array2dasPtr={array2d[0],array2d[1],array2d[2]}
func(array2dasPtr);
}
But that is not either of our codes were doing.
To use your prototype you must do this:
Code:
void func(int (*arr2d)[3][10]);
...
int main(){
int array2d[3][10];
int array3d[5][3][10]
func(&array2d);
func(array3d);
}
To use my prototype you must do this:
Code:
void func(int (&arr2d)[3][10]);
...
int main(){
int array2d[3][10];
int array3d[5][3][10]
func(array2d);
func(array3d[0]);
}