Skip to content

Commit

Permalink
add section on C23doc/manual/R-exts.texi
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87656 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Jan 28, 2025
1 parent c2a2a05 commit 984655d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 6 deletions.
18 changes: 14 additions & 4 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@
\item The deprecated and seemingly never-used S-compatibility
macros \code{F77_COM} and \code{F77_COMDECL} have been removed
from header \file{R_ext/RS.h}.
\item Header \file{R_ext/Rboolean.h} now defines the type
\code{Rboolean} as an alias of the standard C type \code{bool}.
Currently this is done from C (not C++) only if
\code{__bool_true_false_are_defined} is defined, which it is in
C23 mode or if the C99 header \file{stdbool.h} is included.
Before release \file{stdbool.h} will be included from C if C23 mode is
not supported, and C++ \code{bool} will be used if called from
C++.
The macro \code{_R_RBOOLEAN_IS_BOOL_} is defined where
\code{Rboolean} is implemented \emph{via} \code{bool}.
}
}
Expand Down Expand Up @@ -603,10 +617,6 @@
\item \code{as.roman(x)} now should work platform independently,
also for, e.g., \code{x = "IIIII"} (= V) and \code{x = "IIIIII"}
(= VI).

\item \command{R CMD Rd2pdf} works again on an installed package
directory containing \LaTeX help (from option \option{--latex}),
thanks to a report by \I{Peter Ruckdeschel}.
}
}
}
Expand Down
45 changes: 45 additions & 0 deletions doc/manual/R-exts.texi
Original file line number Diff line number Diff line change
Expand Up @@ -6569,6 +6569,51 @@ Another build for Windows which may be sufficiently compatible with
@uref{https://github.com/mstorsjo/llvm-mingw}: this uses @code{libc++}.


@node C23 changes
@subsubsection C23 changes

Thw C23 standard was finally published in Oct 2024, by which time had
been widely implemented for a least a couple of years. It will become
the default on GCC 15, and @R{} will use default to it if available from @R{}
4.5.0.

Some of the more significant changes are
@c https://en.cppreference.com/w/c/23

@itemize

@item
@code{bool}, @code{true} and @code{false} become keywords and so can no
longer be used as identifiers.

These have been available as a boolean type since C99 by including the
header @file{stdbool.h}. Both that and C23@footnote{but C23 declares
that header and the macro to be obsolescent.} set the macro
@code{__bool_true_false_are_defined} to @code{1} so this type can be
used in all versions of C supported by @R{}.

@item
The meaning of an empty argument list has been changed to mean zero
arguments --- however for clarity @code{fun(void)} is still preferred by
many code readers and supported by all C standards. (Compilers may warn
about an empty argument list in C23 mode.)

@item
@code{INIINITY} and @code{NAN} are available via
header @file{float.h} and deprecated in @file{math.h}.

@item
POSIC functions @code{memccpy}, @code{strdup} and @code{strndup} are
part of C23.

@item
There are decimal floating-point types and functions and extended
support of binary floating-point functions, including binary
floating-point constants.
@end itemize



@node Portable Fortran code
@subsection Portable Fortran code

Expand Down
47 changes: 45 additions & 2 deletions src/include/R_ext/Boolean.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 2000, 2001 The R Core Team.
* Copyright (C) 2000, 2025 The R Core Team.
*
* This header file is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -29,13 +29,56 @@
#undef FALSE
#undef TRUE

/* This can eventually be simplified to
#if (!defined __cplusplus) && !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)
# include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C" {
typedef bool Rboolean;
#define FALSE false
#define TRUE true
}
#define _R_RBOOLEAN_IS_BOOL_ 1
#endif
typedef enum { FALSE = 0, TRUE /*, MAYBE */ } Rboolean;
*/

#ifdef __cplusplus

extern "C" {
/* once cp11 is soerted
typedef bool Rboolean;
#define FALSE false
#define TRUE true
*/
typedef enum { FALSE = 0, TRUE } Rboolean;
}

# else

// Also include standard C boolean type
#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
// C23 so these are keywords
#else
// stdbool.h is C99, so available everywhere
//# include <stdbool.h>
#endif

/*
__bool_true_false_are_defined is defined in stdbool.h, and C23, but
it and stdbool.h are declared obsolescent in C23.
*/
#ifdef __bool_true_false_are_defined
typedef bool Rboolean;
# define FALSE false
# define TRUE true
# define _R_RBOOLEAN_IS_BOOL_ 1
#else
typedef enum { FALSE = 0, TRUE } Rboolean;
#endif //__bool_true_false_are_defined

# endif // __cplusplus


#endif /* R_EXT_BOOLEAN_H_ */

0 comments on commit 984655d

Please sign in to comment.