Dear Rcpp-devel list I need your help again to solve a problem I have when submitting a new release of the ade4 package (https://github.com/sdray/ade4) to CRAN. I wrote a C++ function where I need to use a list of lists (see code below). It works perfectly on all platforms, but the Windows and Linux compilers (not the Mac one) raise a warning saying :
Flavor: r-devel-windows-x86_64 testsCpp.cpp:478:28: warning: ISO C++ forbids variable length array 'spl1' [-Wvla] Flavor: r-devel-linux-x86_64-debian-gcc testsCpp.cpp:478:19: warning: variable length arrays are a C99 feature [-Wvla-extension] This warning happens here: testsCpp.cpp: In function 'arma::vec RVintrarandtestCpp(const arma::mat&, const arma::mat&, Rcpp::IntegerVector, int)': testsCpp.cpp:478:28: warning: ISO C++ forbids variable length array 'spl1' [-Wvla] 478 | Rcpp::List spl1[i]; | ^~~~ Here is the C++ code, as you can see I declare a Rcpp::List of Rcpp::List with varying lengths (these lists are used to store the row numbers of a data table that belong to the same levels of a factor). So my question is: what should I do about this warning ? Do I need to find a workaround (which one ?), or should I ignore it ? Sorry for the long message, and thanks in advance for any help... Jean // [[Rcpp::export]] arma::vec RVintrarandtestCpp(const arma::mat & X, const arma::mat & Y, Rcpp::IntegerVector fac, const int nrepet) { /*-------------------------------------------------- Get the number of levels of the factor --------------------------------------------------*/ Rcpp::CharacterVector faclevs = fac.attr("levels"); int nlev = faclevs.length(); /*-------------------------------------------------- List of lists to store the row numbers belonging to each factor level --------------------------------------------------*/ Rcpp::List spl1(nlev); for (i=0; i<nlev; i++) { Rcpp::List spl1[i]; } /*-------------------------------------------------- Fill the list with the row numbers that belong to each factor level --------------------------------------------------*/ for (j=0; j<nlev; j++) { Rcpp::List listej; for (i=0; i<l1; i++) { if (fac(i) == j+1) { listej.push_back(i+1); } } spl1[j] = listej; } —- Jean THIOULOUSE - https://urlz.fr/jmA8 (Lab home page) https://orcid.org/0000-0001-7664-0598 (ORCID page) https://www.springer.com/fr/book/9781493988488 (ade4 Book) https://jthome.thioulouse.fr/ref/ _______________________________________________ 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