From 8e2cc1dbb65a01f927cc6b6e7257a37db9e95a6f Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Thu, 28 Nov 2024 17:54:59 +0100 Subject: [PATCH] P3370R1 Add new library headers from C23 --- source/lib-intro.tex | 11 +++- source/numerics.tex | 45 +++++++++++++++ source/support.tex | 10 +++- source/utilities.tex | 128 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 5 deletions(-) diff --git a/source/lib-intro.tex b/source/lib-intro.tex index 41896bfef3..990ed02a72 100644 --- a/source/lib-intro.tex +++ b/source/lib-intro.tex @@ -1486,12 +1486,19 @@ \pnum The named module \tcode{std.compat} exports the same declarations as the named module \tcode{std}, and -additionally exports declarations in the global namespace +additionally exports +\begin{itemize} +\item +declarations in the global namespace corresponding to the declarations in namespace \tcode{std} that are provided by the \Cpp{} headers for C library facilities~(\tref{headers.cpp.c}), except the explicitly excluded declarations -described in \ref{support.c.headers.other}. +described in \ref{support.c.headers.other} and +\item +declarations provided by +the headers \libheaderref{stdbit.h} and \libheaderref{stdckdint.h}. +\end{itemize} \pnum It is unspecified to which module a declaration in the standard library diff --git a/source/numerics.tex b/source/numerics.tex index 9d4f844781..41bbf30aec 100644 --- a/source/numerics.tex +++ b/source/numerics.tex @@ -16076,3 +16076,48 @@ A, t, d, B, divides{}); \end{codeblock} \end{itemdescr} + +\rSec1[numerics.c]{C compatibility} + +\rSec2[stdckdint.h.syn]{Header \tcode{} synopsis} + +\begin{codeblock} +#define @\libglobal{__STDC_VERSION_STDCKDINT_H__}@ 202311L + +template + bool ckd_add(type1* result, type2 a, type3 b); +template + bool ckd_sub(type1* result, type2 a, type3 b); +template + bool ckd_mul(type1* result, type2 a, type3 b); +\end{codeblock} + +\pnum +\xref{\IsoCUndated{}:2024, 7.20} %% TODO: change to \xrefc{7.20} + +\rSec2[numerics.c.ckdint]{Checked integer operations} + +\indexlibraryglobal{ckd_add}% +\indexlibraryglobal{ckd_sub}% +\indexlibraryglobal{ckd_mul}% +\begin{itemdecl} +template + bool ckd_add(type1* result, type2 a, type3 b); +template + bool ckd_sub(type1* result, type2 a, type3 b); +template + bool ckd_mul(type1* result, type2 a, type3 b); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\mandates +Each of the types \tcode{type1}, \tcode{type2}, and \tcode{type3} is a +cv-unqualified signed or unsigned integer type. + +\pnum +\remarks +Each function template has the same semantics as +the corresponding type-generic macro with the same name +specified in \IsoCUndated{}:2024, 7.20. +\end{itemdescr} diff --git a/source/support.tex b/source/support.tex index cc86ac8247..d31d9d24d5 100644 --- a/source/support.tex +++ b/source/support.tex @@ -6228,16 +6228,18 @@ \libheader{stdalign.h} \\ \libheaderdef{stdarg.h} \\ \libheader{stdatomic.h} \\ +\libheader{stdbit.h} \\ \libheader{stdbool.h} \\ -\libheaderdef{stddef.h} \\ \columnbreak +\libheader{stdckdint.h} \\ +\libheaderdef{stddef.h} \\ \libheaderdef{stdint.h} \\ \libheaderdef{stdio.h} \\ \libheaderdef{stdlib.h} \\ \libheaderdef{string.h} \\ +\columnbreak \libheader{tgmath.h} \\ \libheaderdef{time.h} \\ -\columnbreak \libheaderdef{uchar.h} \\ \libheaderdef{wchar.h} \\ \libheaderdef{wctype.h} \\ @@ -6341,7 +6343,9 @@ \libheaderref{iso646.h}, \libheaderref{stdalign.h},\newline \libheaderref{stdatomic.h}, -\libheaderref{stdbool.h}, and +\libheaderref{stdbit.h}, +\libheaderref{stdbool.h}, +\libheaderref{stdckdint.h}, and\newline \libheaderref{tgmath.h}, each of which has a name of the form diff --git a/source/utilities.tex b/source/utilities.tex index 6719e8a672..ad5fe79cd4 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -15480,3 +15480,131 @@ Otherwise, \tcode{endian::native} is not equal to either \tcode{endian::big} or \tcode{endian::little}. \end{itemdescr} + +\rSec1[stdbit.h.syn]{Header \tcode{} synopsis} + +\begin{codeblock} +#define @\libglobal{__STDC_VERSION_STDBIT_H__}@ 202311L + +#define @\libglobal{__STDC_ENDIAN_BIG__}@ @\seebelow@ +#define @\libglobal{__STDC_ENDIAN_LITTLE__}@ @\seebelow@ +#define @\libglobal{__STDC_ENDIAN_NATIVE__}@ @\seebelow@ + +unsigned int @\libglobal{stdc_leading_zeros_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_leading_zeros_us}@(unsigned short value); +unsigned int @\libglobal{stdc_leading_zeros_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_leading_zeros_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_leading_zeros_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_leading_zeros}@(T value); + +unsigned int @\libglobal{stdc_leading_ones_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_leading_ones_us}@(unsigned short value); +unsigned int @\libglobal{stdc_leading_ones_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_leading_ones_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_leading_ones_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_leading_ones}@(T value); + +unsigned int @\libglobal{stdc_trailing_zeros_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_trailing_zeros_us}@(unsigned short value); +unsigned int @\libglobal{stdc_trailing_zeros_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_trailing_zeros_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_trailing_zeros_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_trailing_zeros}@(T value); + +unsigned int @\libglobal{stdc_trailing_ones_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_trailing_ones_us}@(unsigned short value); +unsigned int @\libglobal{stdc_trailing_ones_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_trailing_ones_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_trailing_ones_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_trailing_ones}@(T value); + +unsigned int @\libglobal{stdc_first_leading_zero_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_first_leading_zero_us}@(unsigned short value); +unsigned int @\libglobal{stdc_first_leading_zero_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_first_leading_zero_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_first_leading_zero_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_first_leading_zero}@(T value); + +unsigned int @\libglobal{stdc_first_leading_one_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_first_leading_one_us}@(unsigned short value); +unsigned int @\libglobal{stdc_first_leading_one_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_first_leading_one_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_first_leading_one_ull}@(unsigned long long int value); +template @\seebelow@ stdc_first_leading_one(T value); + +unsigned int @\libglobal{stdc_first_trailing_zero_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_first_trailing_zero_us}@(unsigned short value); +unsigned int @\libglobal{stdc_first_trailing_zero_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_first_trailing_zero_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_first_trailing_zero_ull}@(unsigned long long int value); +template @\seebelow@ stdc_first_trailing_zero(T value); + +unsigned int @\libglobal{stdc_first_trailing_one_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_first_trailing_one_us}@(unsigned short value); +unsigned int @\libglobal{stdc_first_trailing_one_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_first_trailing_one_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_first_trailing_one_ull}@(unsigned long long int value); +template @\seebelow@ stdc_first_trailing_one(T value); + +unsigned int @\libglobal{stdc_count_zeros_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_count_zeros_us}@(unsigned short value); +unsigned int @\libglobal{stdc_count_zeros_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_count_zeros_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_count_zeros_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_count_zeros}@(T value); + +unsigned int @\libglobal{stdc_count_ones_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_count_ones_us}@(unsigned short value); +unsigned int @\libglobal{stdc_count_ones_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_count_ones_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_count_ones_ull}@(unsigned long long int value); +template @\seebelow@ stdc_count_ones(T value); + +bool @\libglobal{stdc_has_single_bit_uc}@(unsigned char value); +bool @\libglobal{stdc_has_single_bit_us}@(unsigned short value); +bool @\libglobal{stdc_has_single_bit_ui}@(unsigned int value); +bool @\libglobal{stdc_has_single_bit_ul}@(unsigned long int value); +bool @\libglobal{stdc_has_single_bit_ull}@(unsigned long long int value); +template bool @\libglobal{stdc_has_single_bit}@(T value); + +unsigned int @\libglobal{stdc_bit_width_uc}@(unsigned char value); +unsigned int @\libglobal{stdc_bit_width_us}@(unsigned short value); +unsigned int @\libglobal{stdc_bit_width_ui}@(unsigned int value); +unsigned int @\libglobal{stdc_bit_width_ul}@(unsigned long int value); +unsigned int @\libglobal{stdc_bit_width_ull}@(unsigned long long int value); +template @\seebelow@ @\libglobal{stdc_bit_width}@(T value); + +unsigned char @\libglobal{stdc_bit_floor_uc}@(unsigned char value); +unsigned short @\libglobal{stdc_bit_floor_us}@(unsigned short value); +unsigned int @\libglobal{stdc_bit_floor_ui}@(unsigned int value); +unsigned long int @\libglobal{stdc_bit_floor_ul}@(unsigned long int value); +unsigned long long int @\libglobal{stdc_bit_floor_ull}@(unsigned long long int value); +template T @\libglobal{stdc_bit_floor}@(T value); + +unsigned char @\libglobal{stdc_bit_ceil_uc}@(unsigned char value); +unsigned short @\libglobal{stdc_bit_ceil_us}@(unsigned short value); +unsigned int @\libglobal{stdc_bit_ceil_ui}@(unsigned int value); +unsigned long int @\libglobal{stdc_bit_ceil_ul}@(unsigned long int value); +unsigned long long int @\libglobal{stdc_bit_ceil_ull}@(unsigned long long int value); +template T @\libglobal{stdc_bit_ceil}@(T value); +\end{codeblock} + +\pnum +For a function template whose return type is not specified above, +the return type is +an \impldef{return types for \tcode{} functions} unsigned integer type +large enough to represent all possible result values. +Each function template has the same semantics +as the corresponding type-generic function with the same name +specified in \IsoCUndated{}:2024, 7.18. %% change to \xrefc{7.18} + +\pnum +\mandates +\tcode{T} is an unsigned integer type. + +\pnum +Otherwise, +the contents and meaning of the header \libheader{stdbit.h} are the same as +the C standard library header \tcode{}. + +\xref{\IsoCUndated{}:2024, 7.18} %% TODO: change to \xrefc{7.18}