[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 2d VLA argument, void f( int m, int n, int a[m][n] ) ?
From: |
FÖLDY Lajos |
Subject: |
Re: 2d VLA argument, void f( int m, int n, int a[m][n] ) ? |
Date: |
Tue, 11 Aug 2009 11:55:14 +0200 |
On Mon, 10 Aug 2009, denis wrote:
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
- Prev by Date:
2d VLA argument, void f( int m, int n, int a[m][n] ) ?
- Next by Date:
Re: 2d VLA argument, void f( int m, int n, int a[m][n] ) ?
- Previous by thread:
2d VLA argument, void f( int m, int n, int a[m][n] ) ?
- Next by thread:
Re: 2d VLA argument, void f( int m, int n, int a[m][n] ) ?
- Index(es):