[Rd] documentation of .C (PR#9948)

From: <schlather_at_math.uni-goettingen.de>
Date: Wed, 10 Oct 2007 16:35:18 +0200 (CEST)


Full_Name: Martin Schlather
Version: R version 2.7.0 Under development (unstable) (2007-10-01 r43043) OS: Linux
Submission from: (NULL) (91.3.209.203)

Hi,

There are 2 dangers with using 'DUP=FALSE' mentioned:

Would you also mention a third one, namely that values in R are now only referenced whenever possible and not always copied; hence .C(..., DUP=FALSE) may change the values of other local variables.

E.g., with C code

   void addone(double *x) { *x = *x + 1; }

you get   

  x <- as.double(1)
  y <- x
  .C("addone", x, PACKAGE="test", DUP=FALSE)   print(c(x,y))
#[1] 2 2
  

  x <- as.double(1)
  y <- as.double(x)
 .C("addone", x, PACKAGE="test", DUP=FALSE)   print(c(x,y))
#[1] 2 2

  x <- as.double(1)
  y <- as.integer(x)
 .C("addone", x, PACKAGE="test", DUP=FALSE)   print(c(x,y))
#[1] 2 1

Many thanks and kind regards,
Martin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 10 Oct 2007 - 15:15:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Oct 2007 - 11:37:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.