[R-pkg-devel] ISNAN warning [-Wfloat-conversion]

Morgan Morgan morg@n@em@||box @end|ng |rom gm@||@com
Fri Jul 10 11:39:17 CEST 2020


Please see below warning from GCC (rtools 4.0).
I know that the flag "-Wconversion" is not used by default when building
packages in R but I was wondering if the below warning can be avoided by
changing the ISNAN function in the R C API?
The functions R_IsNaN and R_IsNA do not generate these warnings but they
also have  a different behaviour than ISNAN.

test_ISNAN = inline::cfunction(
  verbose = TRUE,
  language = "C",
  cppargs = "-Wconversion",
  sig = c(x = "SEXP"),
  body = "
  if (ISNAN(asReal(x))) {
  return R_NilValue;

Setting PKG_CPPFLAGS to -Wconversion
Compilation argument:
 C:/PROGRA~1/R/R-40~1.0/bin/x64/R CMD SHLIB filed40200e5009.c 2>
"C:/rtools40/mingw64/bin/"gcc  -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG
-Wconversion         -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2
-mstackrealign -c filed40200e5009.c -o filed40200e5009.o
In file included from C:/PROGRA~1/R/R-40~1.0/include/R.h:58,
                 from filed40200e5009.c:1:
filed40200e5009.c: In function 'filed40200e5009':
C:/PROGRA~1/R/R-40~1.0/include/Rinternals.h:1531:18: warning: conversion
from 'double' to 'float' may change value [-Wfloat-conversion]
 #define asReal   Rf_asReal
filed40200e5009.c:8:7: note: in expansion of macro 'ISNAN'
   if (ISNAN(asReal(x))) {
filed40200e5009.c:8:13: note: in expansion of macro 'asReal'
   if (ISNAN(asReal(x))) {
C:/rtools40/mingw64/bin/gcc -shared -s -static-libgcc -o
filed40200e5009.dll tmp.def filed40200e5009.o
-LC:/PROGRA~1/R/R-40~1.0/bin/x64 -lR
Program source:
  1: #include <R.h>
  2: #include <Rdefines.h>
  3: #include <R_ext/Error.h>
  6: SEXP filed40200e5009 ( SEXP x ) {
  8:   if (ISNAN(asReal(x))) {
  9:     Rprintf("Hello");
 10:   }
 11:   return R_NilValue;
 13:   warning("your C program does not return anything!");
 14:   return R_NilValue;
 15: }

Thank you
Best regards,

	[[alternative HTML version deleted]]

More information about the R-package-devel mailing list