From btyner at stat.purdue.edu  Sun Nov 19 15:55:17 2006
From: btyner at stat.purdue.edu (Benjamin Tyner)
Date: Sun, 19 Nov 2006 09:55:17 -0500
Subject: [Rd]  array indexes in C
Message-ID: <45607055.7010900@stat.purdue.edu>

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



[Rd] array indexes in C
Benjamin Tyner