P
puzzlecracker
int a[3][9];
f(a);
void f(int** x)
{
//do something with a
}
f(a);
void f(int** x)
{
//do something with a
}
puzzlecracker said:int a[3][9];
f(a);
void f(int** x)
{
//do something with a
}
Ben said:puzzlecracker said:int a[3][9];
f(a);
void f(int** x)
{
//do something with a
}
You have a type miss-match. [snip]
The reasons are messy.
Ben Bacarisse said:puzzlecracker said:int a[3][9];
f(a);
void f(int** x)
{
//do something with a
}
You have a type miss-match. 'a' is an array (of length 3) whose
elements are arrays of 9 ints. 'f' must be passed a pointer to a
pointer to int. There is no implicit conversion that allows 'a' to be
passed to 'f'.
The parameter could be declared like this:
void f(int x[][9]);
or alternatively,
void f(int (*x)[9]);
The reasons are messy. In most contexts, expressions of type "array
of T" are converted to "pointer to T" (so void f(int *x) is correct
when passing an array of ints) but this conversion applies only to the
outer array type. The 'a' in 'f(a)' is therefore converted to a value
of type "pointer to array of 9 int" and not "pointer to pointer to
int".
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.