On 24/05/2013 07:53, Jan van der Laan wrote:>
> 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?
Don't use Rdefines.h: use Rinternals.h.
Rdefines.h was for compatibility with S code from the 1990s: it is not
kept up to date.
>
> Thanks.
>
> Jan
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595