D
DarelRex
Is it possible to pass a 2-D, statically defined array?
Here's a 1-D example that won't work:
void foo() {
int myArray[MAX_SIZE] ;
bar(myArray);
}
void bar(int *arr) {
arr[5]=arr[7];
}
It won't work because myArray is statically defined. To make it work,
you can change foo's bar() call to this:
bar(&myArray[0]);
Then it works fine!
Any way to apply the same technique with a 2-D array?
void foo() {
int myArray[SIZE_A][SIZE_B] ;
bar(??myArray??);
}
void bar(int **arr) {
arr[5][3]=arr[2][4];
}
One possible workaround is to define myArray as 1-D but use it as 2-D:
void foo() {
int myArray[SIZE_A*SIZE_B] ;
bar(&myArray[0]);
}
void bar(int *arr) {
arr[5*SIZE_B+3]=arr[2*SIZE_B+4];
}
Kind-of inelegant, though.
Thanks for any advice! --Darel
(e-mail address removed)
http://alienryderflex.com
Here's a 1-D example that won't work:
void foo() {
int myArray[MAX_SIZE] ;
bar(myArray);
}
void bar(int *arr) {
arr[5]=arr[7];
}
It won't work because myArray is statically defined. To make it work,
you can change foo's bar() call to this:
bar(&myArray[0]);
Then it works fine!
Any way to apply the same technique with a 2-D array?
void foo() {
int myArray[SIZE_A][SIZE_B] ;
bar(??myArray??);
}
void bar(int **arr) {
arr[5][3]=arr[2][4];
}
One possible workaround is to define myArray as 1-D but use it as 2-D:
void foo() {
int myArray[SIZE_A*SIZE_B] ;
bar(&myArray[0]);
}
void bar(int *arr) {
arr[5*SIZE_B+3]=arr[2*SIZE_B+4];
}
Kind-of inelegant, though.
Thanks for any advice! --Darel
(e-mail address removed)
http://alienryderflex.com