[Rcpp-devel] strange bool conversion?

Daniel Sabanés Bové daniel.sabanesbove at ifspm.uzh.ch
Mon Dec 13 17:30:37 CET 2010


Hi,

I have just discovered an extremely strange behaviour in conversion of
an R logical to a C++ bool. Consider the minimal example:

--- snip ---

library(Rcpp)
library(inline)

## this compiles and loads fine, but is wrong:
wrong <- cxxfunction(signature(x="list") , '
        List input(x);
        const bool a = input[0];
        return wrap(a);
        ' , plugin = "Rcpp")

wrong(list(TRUE))
wrong(list(FALSE))

## this is correct:
correct <- cxxfunction(signature(x="list") , '
        List input(x);
        const bool a = as<bool>(input[0]);
        return wrap(a);
        ' , plugin = "Rcpp")

correct(list(TRUE))
correct(list(FALSE))

--- snap ----

In Rcpp 0.8.9 wrong(list(FALSE)) == TRUE, which is quite surprising to
the user...
Sorry if this already a known feature, but then I would be curious if
this behaviour is really wished?

Thanks in advance,
best regards

Daniel


More information about the Rcpp-devel mailing list