void f( int m, int n, int a[m][n] )
{
... a[j][k] = ...
?
I see claims that this is valid C99, but g++-4.2.1 gives
error: ‘m’ was not declared in this scope
So, how can I make this work ?
I don't care much about the function header or call syntax,
but a[j][k] in the body should work as fast as a[j*n+k] .
(Some suggest boost::multi_array -- anyone have an example of such an f
() with that ?)
cheers
-- denis
> Folks,
> how can I pass a 2d array with sizes, like
>
> void f( int m, int n, int a[m][n] )
> {
> ... a[j][k] = ...
> ?
> I see claims that this is valid C99, but g++-4.2.1 gives
> error: ?m? was not declared in this scope
>
> So, how can I make this work ?
> I don't care much about the function header or call syntax,
> but a[j][k] in the body should work as fast as a[j*n+k] .
> (Some suggest boost::multi_array -- anyone have an example of such an f
> () with that ?)
>
> cheers
> -- denis
>
/tmp> cat 1.c
#include <stdio.h>
void f( int m, int n, int a[m][n] )
{
a[2][3]=12345;
}
int main()
{
int a[5][6];
f(5,6,a);
printf("%d\n", a[2][3]);
}
/tmp> gcc-4.2.3 1.c && ./a.out
12345
So, what is the problem? :-)
regards,
lajos
Yes, it is valid C99. But C++ is based on C89.
regards,
lajos