Pierre, It is not clear what your code is actually trying to do. The following should be equivalent (as best as I can tell), works (!!) and makes life a lot easier via Attributes.
------- save this as eg /tmp/pierre.cpp ------------------------------------- #include <Rcpp.h> // [[Rcpp::export]] Rcpp::List newCompQuant(int n, int M, Rcpp::Function f) { Rcpp::Rcout << "n : " << n << std::endl << "M : " << M << std::endl; return Rcpp::List::create(Rcpp::Named("sample") = f, Rcpp::Named("law.name") = " ", Rcpp::Named("law.pars") = R_NilValue); } /*** R res <- newCompQuant(n=50, M=10^3, f=norm) print(str(res)) */ ----------------------------------------------------------------------------- In R, then do R> Rcpp::sourceCpp("/tmp/pierre.cpp") for which I then get: R> sourceCpp("/tmp/pierre.cpp") R> res <- newCompQuant(n=50, M=10^3, f=rnorm) n : 50 M : 1000 R> print(str(res)) List of 3 $ sample :function (n, mean = 0, sd = 1) $ law.name: chr " " $ law.pars: NULL NULL R> Attributes also take care of RNGScope, and past discussions here have seen it help with repeated calls (with a 'big' N of number of repeats) where manually dealing with scope and temp objects may otherwise create a wrinkle. Hth, Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel