Skip to content

Commit 984655d

Browse files
author
ripley
committed
add section on C23doc/manual/R-exts.texi
git-svn-id: https://svn.r-project.org/R/trunk@87656 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent c2a2a05 commit 984655d

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

doc/NEWS.Rd

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@
281281
\item The deprecated and seemingly never-used S-compatibility
282282
macros \code{F77_COM} and \code{F77_COMDECL} have been removed
283283
from header \file{R_ext/RS.h}.
284+
285+
\item Header \file{R_ext/Rboolean.h} now defines the type
286+
\code{Rboolean} as an alias of the standard C type \code{bool}.
287+
288+
Currently this is done from C (not C++) only if
289+
\code{__bool_true_false_are_defined} is defined, which it is in
290+
C23 mode or if the C99 header \file{stdbool.h} is included.
291+
292+
Before release \file{stdbool.h} will be included from C if C23 mode is
293+
not supported, and C++ \code{bool} will be used if called from
294+
C++.
295+
296+
The macro \code{_R_RBOOLEAN_IS_BOOL_} is defined where
297+
\code{Rboolean} is implemented \emph{via} \code{bool}.
284298
}
285299
}
286300
@@ -603,10 +617,6 @@
603617
\item \code{as.roman(x)} now should work platform independently,
604618
also for, e.g., \code{x = "IIIII"} (= V) and \code{x = "IIIIII"}
605619
(= VI).
606-
607-
\item \command{R CMD Rd2pdf} works again on an installed package
608-
directory containing \LaTeX help (from option \option{--latex}),
609-
thanks to a report by \I{Peter Ruckdeschel}.
610620
}
611621
}
612622
}

doc/manual/R-exts.texi

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,6 +6569,51 @@ Another build for Windows which may be sufficiently compatible with
65696569
@uref{https://github.com/mstorsjo/llvm-mingw}: this uses @code{libc++}.
65706570

65716571

6572+
@node C23 changes
6573+
@subsubsection C23 changes
6574+
6575+
Thw C23 standard was finally published in Oct 2024, by which time had
6576+
been widely implemented for a least a couple of years. It will become
6577+
the default on GCC 15, and @R{} will use default to it if available from @R{}
6578+
4.5.0.
6579+
6580+
Some of the more significant changes are
6581+
@c https://en.cppreference.com/w/c/23
6582+
6583+
@itemize
6584+
6585+
@item
6586+
@code{bool}, @code{true} and @code{false} become keywords and so can no
6587+
longer be used as identifiers.
6588+
6589+
These have been available as a boolean type since C99 by including the
6590+
header @file{stdbool.h}. Both that and C23@footnote{but C23 declares
6591+
that header and the macro to be obsolescent.} set the macro
6592+
@code{__bool_true_false_are_defined} to @code{1} so this type can be
6593+
used in all versions of C supported by @R{}.
6594+
6595+
@item
6596+
The meaning of an empty argument list has been changed to mean zero
6597+
arguments --- however for clarity @code{fun(void)} is still preferred by
6598+
many code readers and supported by all C standards. (Compilers may warn
6599+
about an empty argument list in C23 mode.)
6600+
6601+
@item
6602+
@code{INIINITY} and @code{NAN} are available via
6603+
header @file{float.h} and deprecated in @file{math.h}.
6604+
6605+
@item
6606+
POSIC functions @code{memccpy}, @code{strdup} and @code{strndup} are
6607+
part of C23.
6608+
6609+
@item
6610+
There are decimal floating-point types and functions and extended
6611+
support of binary floating-point functions, including binary
6612+
floating-point constants.
6613+
@end itemize
6614+
6615+
6616+
65726617
@node Portable Fortran code
65736618
@subsection Portable Fortran code
65746619

src/include/R_ext/Boolean.h

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* R : A Computer Language for Statistical Data Analysis
3-
* Copyright (C) 2000, 2001 The R Core Team.
3+
* Copyright (C) 2000, 2025 The R Core Team.
44
*
55
* This header file is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -29,13 +29,56 @@
2929
#undef FALSE
3030
#undef TRUE
3131

32+
/* This can eventually be simplified to
33+
#if (!defined __cplusplus) && !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)
34+
# include <stdbool.h>
35+
#endif
36+
3237
#ifdef __cplusplus
3338
extern "C" {
39+
typedef bool Rboolean;
40+
#define FALSE false
41+
#define TRUE true
42+
}
43+
#define _R_RBOOLEAN_IS_BOOL_ 1
3444
#endif
35-
typedef enum { FALSE = 0, TRUE /*, MAYBE */ } Rboolean;
45+
*/
3646

3747
#ifdef __cplusplus
48+
49+
extern "C" {
50+
/* once cp11 is soerted
51+
typedef bool Rboolean;
52+
#define FALSE false
53+
#define TRUE true
54+
*/
55+
typedef enum { FALSE = 0, TRUE } Rboolean;
3856
}
57+
58+
# else
59+
60+
// Also include standard C boolean type
61+
#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
62+
// C23 so these are keywords
63+
#else
64+
// stdbool.h is C99, so available everywhere
65+
//# include <stdbool.h>
3966
#endif
4067

68+
/*
69+
__bool_true_false_are_defined is defined in stdbool.h, and C23, but
70+
it and stdbool.h are declared obsolescent in C23.
71+
*/
72+
#ifdef __bool_true_false_are_defined
73+
typedef bool Rboolean;
74+
# define FALSE false
75+
# define TRUE true
76+
# define _R_RBOOLEAN_IS_BOOL_ 1
77+
#else
78+
typedef enum { FALSE = 0, TRUE } Rboolean;
79+
#endif //__bool_true_false_are_defined
80+
81+
# endif // __cplusplus
82+
83+
4184
#endif /* R_EXT_BOOLEAN_H_ */

0 commit comments

Comments
 (0)