[R-pkg-devel] Compiling error with the new R.h header (R-devel 3.3.0 for Windows) when using the C++ function isnan() of <math.h>

Martyn Plummer plummerm at iarc.fr
Wed Apr 20 15:22:05 CEST 2016


Short answer: use the R macro ISNAN instead. See the Writing R
Extensions manual for details.

Long answer: The default standard for C++ code in R packages is C++98,
which does not define a function "isnan". The C++11 standard introduced
a std::isnan function to C++. What you were previously getting from the
inclusion of the legacy header <math.h> was a C99 macro. Now the C++
header <cmath> is used instead of the legacy header <math.h> you should
stick to the standard. 

Martyn


On Wed, 2016-04-20 at 14:28 +0200, Antonio Canale wrote:
> Dear all,
> 
> my problem is related to the new version of my msBP package but it
> actually applies also to the current version uploaded on CRAN
> (https://cran.r-project.org/web/checks/check_results_msBP.html).
> 
> It turns out that the package cannot be compiled under the new R-
> devel
> for windows.
> 
> The problem is related to the isnan() function of <math.h> library of
> C++ which I call twice in one of my C++ scripts.
> 
> Consider the function below as MWE
> 
> #include<stdio.h>
> #include<stdlib.h>
> #include<math.h>
> #include<R.h>
> #include<Rmath.h>
> extern "C"{
> void gibbs(double *A)
> {
> if(isnan(A[i]) || (A[i]<=0))
> { do stuff }
> }
> }
> 
> Precisely, the error that I get is reported at
> https://www.r-project.org/nosvn/R.check/r-devel-windows-ix86+x86_64/m
> sBP-00install.html
> 
> I've have found in the R-devel blog and check myself that from R
> version 3.3.0 the header  file R.h is changed. In particular it is
> now
> going to include the C++ versions of system header ‘<cmath>’ rather
> than the legacy header ‘<math.h> which seems to be the source of my
> problem.
> 
> However I cannot understand why it causes the error and in particular
> why it is happening *only under windows* and not under other OS. I've
> check my new package both in OS X and Ubuntu (with R-devel) and
> everything is OK. It also compiles fine in Windows under R.3.2.5.
> 
> Thanks for your help.
> 
> Best,
> Antonio
> 
> --
> Antonio Canale
> University of Turin and
> Collegio Carlo Alberto
> sites.carloalberto.org/canale
> 
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel


More information about the R-package-devel mailing list