[Rcpp-devel] bool from list: unexpected result and differences between compilers/OSs

Dirk Eddelbuettel edd at debian.org
Mon Jun 22 13:21:03 CEST 2015


On 22 June 2015 at 10:25, Ramon Diaz-Uriarte wrote:
| 
| Dear All,
| 
| Accessing an element of a list that should be TRUE/FALSE does not recognize
| the boolean properly in Windows/gcc-4.6.3 unless I use "as". It does the
| same surprising thing in Debian Linux with gcc-4.6.4.
| 
| But it does do what I expect in Linux, with both gcc (4.9.2) and
| clang++-libc++ (3.5.2-1). In Windows, I am using Rtools33.exe, the latest
| Rtools.exe (downloaded last night). 
| 
| 
| 
| Given the above, is it the proper way to proceed to always use "as<bool>"?
| Or, just being extra careful, should we "as<whatever>" (double, int, etc)?

R has TRUE, FALSE and NA in a logical -- three values.  That can breaks
automagic conversion to bool.  So I think as<bool> is a safe bet here.  In
general, in does not hurt to help the compiler -- but you don't always have
to do it. Also, for bool, you can test explicitly for FALSE (or TRUE, or NA)
though.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list