[Rcpp-devel] sugar under Wingows/g++ (MinGW) odd behavior.

Romain Francois romain at r-enthusiasts.com
Sat Jan 15 10:15:52 CET 2011


Le 13/01/11 16:29, Dominick Samperi a écrit :
> The template expression code is very interesting, but it
> does not work as expected under
> Windows/g++/MinGW/32bit/Rterm.exe. The problem
> does not appear when I use Rgui.exe, or if I use
> 64bit Windows!
>
> Consider the following C++ code called using
> .Call('testsugar',1:5,1:5):
>
> RcppExport SEXP testsugar(SEXP x_, SEXP y_) {
>      Rcpp::NumericVector x(x_), y(y_);
>      Rprintf("%d, %lf, %lf\n", (x+y).size(), (x+y)[0], (x+y)[1]);
>      return R_NilValue;
> }
>
> Under Linux/GCC, or 64bit Windows/g++, or
> 32bit Windows/g++ I get the expected result:
>
> 5, 2.0, 4.0
>
> Under Windows/32bit/Rterm.exe I get:
>
> 5, 0.0, 0.0

Intriguing. Maybe Rprintf is to blame. Can you try this instead:

RcppExport SEXP testsugar(SEXP x_, SEXP y_) {
     Rcpp::NumericVector x(x_), y(y_);
	int n = (x+y).size() ;
	double xy0 = (x+y)[0] ;
	double xy1 = (x+y)[1] ;
     Rprintf("%d, %lf, %lf\n", n, xy0, xy1);
     return R_NilValue;
}

> (Under VC++ there are more serious problems including
> corruption of other in the wrap-up function
> Vector(VectorBase& other), but since VC++ is not
> supported I will not elaborate here.)
>
> Thanks,
> Dominick


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/fT2rZM : highlight 0.2-5
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
`- http://bit.ly/hovakS : RcppGSL initial release




More information about the Rcpp-devel mailing list