On 1/30/25 22:07, Michael Chirico wrote:
Hello all,
The recent change (r87656) to make Rboolean map to type 'bool', not
'int', broke some tests & made me realize I've had totally the wrong
impression about what Rboolean actually is, and I suspect I'm not
alone.
Till now, I've assumed that like Rbyte --> RAWSXP, Rboolean is the
_correct_ storage type for LGLSXP, while idioms like int *ip =
LOGICAL(...) only "happened to work" because Rboolean masks int, which
could change at any time.
Actually, it turns out Rboolean only "happened to be int" because of
the use of 'enum', which is changing in now-and-future C standards!
We made that mistake in 9 places [1], though only one happened to
break tests. There are at least dozens of other cases on CRAN [2],[3].
Here's the current exposition on Rboolean in R-exts [4]:
Further, the included header R_ext/Boolean.h has enumeration constants TRUE and
FALSE of type Rboolean in order to provide a way of using “logical” variables
in C consistently. This can conflict with other software: for example it
conflicts with the headers in IJG’s jpeg-9 (but not earlier versions).
I suggest embellishing this, perhaps like so:
Further, the included header R_ext/Boolean.h has enumeration constants TRUE and FALSE of
type Rboolean in order to provide a way of using “logical” variables in C consistently.
This has no concept of "missingness", and so is \emph{not} related to the R
logical type LGLSXP. This can conflict with other software: for example it conflicts with
the headers in IJG’s jpeg-9 (but not earlier versions).
Probably worth an extra sentence making this more explicit. I've added
one similar to your suggestion.
Tomas
It would also be nice if this mistake could be caught by the compiler,
but that's another issue.
Michael Chirico
[1] https://github.com/Rdatatable/data.table/pull/6782/files
[2] https://github.com/search?q=org%3Acran+%2FRboolean.*%5CbLOGICAL%2F&type=code
[3]
https://github.com/search?q=org%3Acran+%2FLOGICAL.*sizeof%5B%28%5DRboolean%2F&type=code
[4]
https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Mathematical-constants
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel