[R-pkg-devel] use of assert in C++

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Thu Dec 19 12:35:09 CET 2024


On 19 December 2024 at 06:06, Duncan Murdoch wrote:
| I think it would be really misleading to have code that routinely 
| ignored the assert() calls. In a year would you remember that those 
| asserts were effectively just comments, not being acted on without some 
| trickery to enable them?

Or have a user with different compiler flags without the NDEBUG ... and now
you have different behavior on different installation which is not great.

| You'd be much safer if you used a different function specific to R that 
| triggered an R error if the assertion was false.

Seconded.

We trade run-time and compile-time off in other ways so this should be a
run-time check, with e.g. Rf_error() or Rcpp::stop() returning to the R
prompt with an error message. If you feel you must program your C++
components with assert() you could still do so in an external library
effectively hiding it from CRAN check. But that's cheating.

Dirk

-- 
dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-package-devel mailing list