[R] using the .C interface to call compiled C code

Faheem Mitha faheem at email.unc.edu
Fri Feb 23 07:35:11 CET 2001

Dear People,

I have been trying to learn how to use the .C interface. A friend gave me
a toy example, and I have been playing with it. It is 

(C code)

#ifdef USING_R
  typedef int Sint;
  typedef long Sint;

void kosum(double *a, double *b, Sint *na) 
  int i, j, nab;
  double temp;
  for(i=0;i < nab; i++)

And the calling code in R is 

function(a, b)
                b = double(1),

Now, I noticed that if I change

for(i=0;i < nab; i++) to say for(i=0;i <= nab; i++) or even  
for(i=0;i <= nab + 1; i++)

everything seems happy, and I get the same answers. But I don't understand
why this is so. I am surely trying to read from nonexistent memory in this
case, and I should have some problems.

I may be missing the obvious, but I am neither very experienced in R or in

Also, if anyone has a simple example of using .C that they would like to
share with me, or if they can point to me to (very) simple examples in the
source code that would be suitable for an beginner, I would be extremely

                           Sincerely, Faheem Mitha.

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list