Dirk, apologies, i meant to sent it to R-devel, i just replied to wrong list. Now that i read responses on both lists, i am confused. Simon Urbanek seemed to indicate that call by reference from<br>R to C++ is impossible with .C interface and dangerous and unreliable with .Call. If i understood you correctly you seem to say that Rcpp facilitates call by reference from R to C++. I actually tried that<br>
in Rcpp as well but didn&#39;t succeed either, may be you could point me in the right direction. Here is what i tried<br><br><br>modify.cpp<br>===========================<br>#include &lt;Rcpp.h&gt;<br>
#include &lt;RcppArmadillo.h&gt;<br>
#include &lt;armadillo&gt;<br>
using namespace Rcpp;<br>
using namespace arma;<br>
<br>
RcppExport void modify(SEXP mem){<br>
  mat m=as&lt;mat&gt;(mem);<br>
  m.print();<br>
  m=m+m;<br> 
<br>
}<br>==========================<br>I compiled the above, pointing  to RccpArmadillo include dir and linked shared library to armadillo code. Then i loaded shared library and tried to run code from R as follows<br><br><br>

&gt;dyn.load(&quot;/home/az05625/testarma/passptr.so&quot;)<br>
&gt; .Call(&quot;modify&quot;, m)<br><br>matrix m prints out fine, but code segfaults on the last statement m=m+m<br>Could you give me some idea on how to fix this?<br><br><br><br><br><br><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Please ask basic R programming questions on R-devel as you seem to have read<br>
the wrong documentation --- there is no support for .C() in Rcpp. We do what<br>
we do via SEXP objects, and those require .Call().  So I suggest you read a<br>
little more in &quot;Writing R Extensions&quot;.  As well as the Rcpp documentation.<br>
<br>
And as you will learn in the &quot;Rcpp-introduction&quot; and other places, we use<br>
what is called proxy model --- so yes, we do pass pointers and no, you don;t<br>
get more lightweight than this.<br>
<br>
Then again, R uses copy-on-write so if you want to truly alter without having<br>
R create new copies for you then external pointers are your best bet.<br>
<br>
Dirk<br>
<font color="#888888"><br>
--<br>
&quot;Outside of a dog, a book is a man&#39;s best friend. Inside of a dog, it is too<br>
dark to read.&quot; -- Groucho Marx<br>
</font></blockquote><div class="h5"><br>
</div></div><br>