Skip to content

Commit c2e8e6f

Browse files
author
ripley
committed
add R_INCLUDE_BOOLEAN_H=0
git-svn-id: https://svn.r-project.org/R/trunk@88052 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 3598239 commit c2e8e6f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

doc/NEWS.Rd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
also seen for \code{nullptr} (C23 and C++11). Masking these by
4646
macros \emph{may} generate correct code (but not always) and always
4747
results in confusing-to-read code.
48+
%% Someone defined 'true' as -1, for example.
4849
}
4950
}
5051

@@ -504,6 +505,17 @@
504505
declaration for \code{F77_SUB(interv)}. This is intended to be
505506
called from Fortran and was wrongly declared: \code{LOGICAL} in
506507
Fortran corresponds to \code{int *} not \code{Rboolean *}.
508+
509+
\item Defining \code{R_INCLUDE_BOOLEAN_H} to \code{0} before
510+
including headers \file{R.h} or \file{Rinternals.h} (or any other
511+
header which includes \file{R_ext/Boolean.h}) stops the inclusion
512+
of header \code{R_ext/Boolean.h} which `defines' constants
513+
\code{TRUE}, \code{true}, \code{false} and the type \code{bool}
514+
which some package maintainers wish to avoid.
515+
516+
Note that the last three are keywords in C23 and C++11 so cannot be
517+
avoided entirely. However, with commonly-used compilers they can be
518+
masked by a macro of the same name, often with a warning.
507519
}
508520
}
509521

src/include/R_ext/Boolean.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#ifndef R_EXT_BOOLEAN_H_
2727
#define R_EXT_BOOLEAN_H_
28+
#if !defined(R_INCLUDE_BOOLEAN_H) || R_INCLUDE_BOOLEAN_H
2829

2930
// NB: there is a version of this in Rmath.h0[.in]
3031

@@ -73,4 +74,12 @@ extern "C" {
7374
}
7475
#endif
7576

77+
#else
78+
/* The Rbolean type is used in too many R headers to condition them
79+
* all. However, people defining R_INCLUDE_BOOLEAN_H=0 should not be
80+
* using it in their own code, and its base type is expected to be int
81+
* (and guaranteed to be on most platforms as from R 4.5.0). */
82+
83+
typedef Rboolean int;
84+
#endif /* R_INCLUDE_BOOLEAN_H = 0 */
7685
#endif /* R_EXT_BOOLEAN_H_ */

0 commit comments

Comments
 (0)