I am trying to use R_RegisterCFinalizerEx to ensure some c++ object is properly deleted after use. However, I run into some problems when trying to pass in the third argument which is an Rboolean. The line 'R_RegisterCFinalizerEx(p, finalizer, TRUE);' generates the following error when trying to compile using R CMD SHLIB:

g++ -I/usr/share/R/include -DNDEBUG -fpic -O2 -pipe -g -c rboolean.cpp -o rboolean.o
rboolean.cpp: In function ?SEXPREC* create(SEXP)?:
rboolean.cpp:21:46: error: invalid conversion from ?int? to ?Rboolean? [-fpermissive]
In file included from /usr/share/R/include/Rdefines.h:29:0,
                 from rboolean.cpp:4:
/usr/share/R/include/Rinternals.h:764:6: error: initializing argument 3 of ?void R_RegisterCFinalizerEx(SEXP, R_CFinalizer_t, Rboolean)? [-fpermissive]
make: *** [rboolean.o] Error 1


I have managed to reduce the problem to the example below:

===== foo.cpp =====
#include <R.h>
#include <Rdefines.h>

void foo() {
  Rboolean b = TRUE;
}
==================

With the extension .cpp this generates the error above, with the extension .c (don't put both in the same directory; at least not with the same name) it compiles without errors or warnings.

When looking at the headers (R_ext/Boolean.h and Rdefines.h) it seems that TRUE and FALSE are also defined as constants which seems to conflict with the enum values of Rboolean.

For now I use the compiler flag -fpermissive (as suggested by g++), but I suppose this is not acceptable when submitting to CRAN. Am I doing something wrong? Is there a workaround/solution?

Thanks.

Jan

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to