From tpapp at Princeton.EDU  Sun Nov 19 16:01:23 2006
From: tpapp at Princeton.EDU (Tamas K Papp)
Date: Sun, 19 Nov 2006 10:01:23 -0500
Subject: [Rd] array indexes in C
In-Reply-To: <45607055.7010900@stat.purdue.edu>
References: <45607055.7010900@stat.purdue.edu>
Message-ID: <20061119150123.GA4592@pu100877.student.princeton.edu>

Hi Ben,

Thanks for your answer.  I looked at the status of VLA on the GCC
homepage and it appears to be "broken". [1] Do you think that the code
below still works?  Or are you using a different compliler?

Thanks,

Tamas

[1] http://gcc.gnu.org/c99status.html


On Sun, Nov 19, 2006 at 09:55:17AM -0500, Benjamin Tyner wrote:
> Tamas,
> 
> You could write convenience functions, but I have used the C99 mechanism 
> for variable length arrays with no problems calling from R. One thing 
> you have to keep in mind though is that (as far as I know) the 
> dimensions must be passed before the array reference. So for example,
> 
> r <- .C("foo",
>               as.integer(ni),
>               as.integer(nj),
>               x = double(ni * nj),
>               ...)
> 
> with your function defined as
> 
> void foo(int *ni, int *nj, double x[*ni][*nj])
> {
> ...
> 
> Then in C you can access elements of x via x[3][4], for example.
> 
> Ben
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] array indexes in C
Tamas K Papp