This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

88
cppdraft/c/files.md Normal file
View File

@@ -0,0 +1,88 @@
[c.files]
# 31 Input/output library [[input.output]](./#input.output)
## 31.13 C library files [c.files]
### [31.13.1](#cstdio.syn) Header <cstdio> synopsis [[cstdio.syn]](cstdio.syn)
[🔗](#header:%3ccstdio%3e)
#define __STDC_VERSION_STDIO_H__ 202311Lnamespace std {using size_t = *see [[support.types.layout]](support.types.layout "17.2.4Sizes, alignments, and offsets")*; using FILE = *see below*; using fpos_t = *see below*;}#define NULL *see [[support.types.nullptr]](support.types.nullptr "17.2.3Null pointers")*#define _IOFBF *see below*#define _IOLBF *see below*#define _IONBF *see below*#define BUFSIZ *see below*#define EOF *see below*#define FOPEN_MAX *see below*#define FILENAME_MAX *see below*#define _PRINTF_NAN_LEN_MAX *see below*#define L_tmpnam *see below*#define SEEK_CUR *see below*#define SEEK_END *see below*#define SEEK_SET *see below*#define TMP_MAX *see below*#define stderr *see below*#define stdin *see below*#define stdout *see below*namespace std {int remove(const char* filename); int rename(const char* old_p, const char* new_p);
FILE* tmpfile(); char* tmpnam(char* s); int fclose(FILE* stream); int fflush(FILE* stream);
FILE* fopen(const char* filename, const char* mode);
FILE* freopen(const char* filename, const char* mode, FILE* stream); void setbuf(FILE* stream, char* buf); int setvbuf(FILE* stream, char* buf, int mode, size_t size); int fprintf(FILE* stream, const char* format, ...); int fscanf(FILE* stream, const char* format, ...); int printf(const char* format, ...); int scanf(const char* format, ...); int snprintf(char* s, size_t n, const char* format, ...); int sprintf(char* s, const char* format, ...); int sscanf(const char* s, const char* format, ...); int vfprintf(FILE* stream, const char* format, va_list arg); int vfscanf(FILE* stream, const char* format, va_list arg); int vprintf(const char* format, va_list arg); int vscanf(const char* format, va_list arg); int vsnprintf(char* s, size_t n, const char* format, va_list arg); int vsprintf(char* s, const char* format, va_list arg); int vsscanf(const char* s, const char* format, va_list arg); int fgetc(FILE* stream); char* fgets(char* s, int n, FILE* stream); int fputc(int c, FILE* stream); int fputs(const char* s, FILE* stream); int getc(FILE* stream); int getchar(); int putc(int c, FILE* stream); int putchar(int c); int puts(const char* s); int ungetc(int c, FILE* stream);
size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream); int fgetpos(FILE* stream, fpos_t* pos); int fseek(FILE* stream, long int offset, int whence); int fsetpos(FILE* stream, const fpos_t* pos); long int ftell(FILE* stream); void rewind(FILE* stream); void clearerr(FILE* stream); int feof(FILE* stream); int ferror(FILE* stream); void perror(const char* s);}
[1](#cstdio.syn-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L18970)
The contents and meaning of the header [<cstdio>](#header:%3ccstdio%3e "31.13.1Header <cstdio> synopsis[cstdio.syn]") are the same as the C standard library header [<stdio.h>](support.c.headers.general#header:%3cstdio.h%3e "17.15.1General[support.c.headers.general]")[.](#cstdio.syn-1.sentence-1)
[2](#cstdio.syn-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L18974)
The return from each function call
that delivers data
to the host environment
to be written to a file (See also: ISO/IEC 9899:2024, 7.21.3)
is an observable checkpoint ([[intro.abstract]](intro.abstract "4.1.2Abstract machine"))[.](#cstdio.syn-2.sentence-1)
[3](#cstdio.syn-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L18981)
Calls to the function tmpnam with an argument that is a null pointer value may
introduce a data race ([[res.on.data.races]](res.on.data.races "16.4.6.10Data race avoidance")) with other calls to tmpnam with
an argument that is a null pointer value[.](#cstdio.syn-3.sentence-1)
See also: ISO/IEC 9899:2024, 7.23
### [31.13.2](#cinttypes.syn) Header <cinttypes> synopsis [[cinttypes.syn]](cinttypes.syn)
[🔗](#header:%3ccinttypes%3e)
#include <cstdint> // see [[cstdint.syn]](cstdint.syn "17.4.1Header <cstdint> synopsis")namespace std {using imaxdiv_t = *see below*; constexpr intmax_t imaxabs(intmax_t j); constexpr imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
intmax_t strtoimax(const char* nptr, char** endptr, int base);
uintmax_t strtoumax(const char* nptr, char** endptr, int base);
intmax_t wcstoimax(const wchar_t* nptr, wchar_t** endptr, int base);
uintmax_t wcstoumax(const wchar_t* nptr, wchar_t** endptr, int base); constexpr intmax_t abs(intmax_t); // optional, see belowconstexpr imaxdiv_t div(intmax_t, intmax_t); // optional, see below}#define __STDC_VERSION_INTTYPES_H__ 202311L#define PRId*N* *see below*#define PRIi*N* *see below*#define PRIo*N* *see below*#define PRIu*N* *see below*#define PRIx*N* *see below*#define PRIX*N* *see below*#define PRIb*N* *see below*#define PRIB*N* *see below*#define SCNd*N* *see below*#define SCNi*N* *see below*#define SCNo*N* *see below*#define SCNu*N* *see below*#define SCNx*N* *see below*#define SCNb*N* *see below*#define PRIdLEAST*N* *see below*#define PRIiLEAST*N* *see below*#define PRIoLEAST*N* *see below*#define PRIuLEAST*N* *see below*#define PRIxLEAST*N* *see below*#define PRIXLEAST*N* *see below*#define PRIbLEAST*N* *see below*#define PRIBLEAST*N* *see below*#define SCNdLEAST*N* *see below*#define SCNiLEAST*N* *see below*#define SCNoLEAST*N* *see below*#define SCNuLEAST*N* *see below*#define SCNxLEAST*N* *see below*#define SCNbLEAST*N* *see below*#define PRIdFAST*N* *see below*#define PRIiFAST*N* *see below*#define PRIoFAST*N* *see below*#define PRIuFAST*N* *see below*#define PRIxFAST*N* *see below*#define PRIXFAST*N* *see below*#define PRIbFAST*N* *see below*#define PRIBFAST*N* *see below*#define SCNdFAST*N* *see below*#define SCNiFAST*N* *see below*#define SCNoFAST*N* *see below*#define SCNuFAST*N* *see below*#define SCNxFAST*N* *see below*#define SCNbFAST*N* *see below*#define PRIdMAX *see below*#define PRIiMAX *see below*#define PRIoMAX *see below*#define PRIuMAX *see below*#define PRIxMAX *see below*#define PRIXMAX *see below*#define PRIbMAX *see below*#define PRIBMAX *see below*#define SCNdMAX *see below*#define SCNiMAX *see below*#define SCNoMAX *see below*#define SCNuMAX *see below*#define SCNxMAX *see below*#define SCNbMAX *see below*#define PRIdPTR *see below*#define PRIiPTR *see below*#define PRIoPTR *see below*#define PRIuPTR *see below*#define PRIxPTR *see below*#define PRIXPTR *see below*#define PRIbPTR *see below*#define PRIBPTR *see below*#define SCNdPTR *see below*#define SCNiPTR *see below*#define SCNoPTR *see below*#define SCNuPTR *see below*#define SCNxPTR *see below*#define SCNbPTR *see below*
[1](#cinttypes.syn-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L19133)
The contents and meaning of the header [<cinttypes>](#header:%3ccinttypes%3e "31.13.2Header <cinttypes> synopsis[cinttypes.syn]") are the same as the C standard library header [<inttypes.h>](support.c.headers.general#header:%3cinttypes.h%3e "17.15.1General[support.c.headers.general]"),
with the following changes:
- [(1.1)](#cinttypes.syn-1.1)
The header [<cinttypes>](#header:%3ccinttypes%3e "31.13.2Header <cinttypes> synopsis[cinttypes.syn]") includes the header [<cstdint>](cstdint.syn#header:%3ccstdint%3e "17.4.1Header <cstdint> synopsis[cstdint.syn]") instead
of [<stdint.h>](support.c.headers.general#header:%3cstdint.h%3e "17.15.1General[support.c.headers.general]"), and
- [(1.2)](#cinttypes.syn-1.2)
if and only if the type intmax_t designates an extended integer
type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types")), the following function signatures are added:constexpr intmax_t abs(intmax_t);constexpr imaxdiv_t div(intmax_t, intmax_t); which shall have the same semantics as the function signaturesconstexpr intmax_t imaxabs(intmax_t) andconstexpr imaxdiv_t imaxdiv(intmax_t, intmax_t), respectively[.](#cinttypes.syn-1.sentence-1)
See also: ISO/IEC 9899:2024, 7.8
[2](#cinttypes.syn-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L19155)
Each of the PRI macros listed in this subclause
is defined if and only if the implementation
defines the corresponding [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4The typedef specifier[dcl.typedef]") in [[cstdint.syn]](cstdint.syn "17.4.1Header <cstdint> synopsis")[.](#cinttypes.syn-2.sentence-1)
Each of the SCN macros listed in this subclause
is defined if and only if the implementation
defines the corresponding [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4The typedef specifier[dcl.typedef]") in [[cstdint.syn]](cstdint.syn "17.4.1Header <cstdint> synopsis") and
has a suitable fscanf length modifier for the type[.](#cinttypes.syn-2.sentence-2)
Each of the PRIB macros listed in this subclause
is defined if and only if fprintf supports
the B conversion specifier[.](#cinttypes.syn-2.sentence-3)

45
cppdraft/c/locales.md Normal file
View File

@@ -0,0 +1,45 @@
[c.locales]
# 28 Text processing library [[text]](./#text)
## 28.3 Localization library [[localization]](localization#c.locales)
### 28.3.5 C library locales [c.locales]
#### [28.3.5.1](#clocale.syn) Header <clocale> synopsis [[clocale.syn]](clocale.syn)
[🔗](#lib:lconv)
namespace std {struct lconv; char* setlocale(int category, const char* locale);
lconv* localeconv();}#define NULL *see [[support.types.nullptr]](support.types.nullptr "17.2.3Null pointers")*#define LC_ALL *see below*#define LC_COLLATE *see below*#define LC_CTYPE *see below*#define LC_MONETARY *see below*#define LC_NUMERIC *see below*#define LC_TIME *see below*
[1](#clocale.syn-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4920)
The contents and meaning of the header <clocale> are the same as the C standard library header [<locale.h>](support.c.headers.general#header:%3clocale.h%3e "17.15.1General[support.c.headers.general]")[.](#clocale.syn-1.sentence-1)
#### [28.3.5.2](#clocale.data.races) Data races [[clocale.data.races]](clocale.data.races)
[1](#clocale.data.races-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4926)
Calls to the function setlocale may introduce a data race ([[res.on.data.races]](res.on.data.races "16.4.6.10Data race avoidance"))
with other calls to setlocale or
with calls to the functions listed in Table [103](#tab:setlocale.data.races "Table 103: Potential setlocale data races")[.](#clocale.data.races-1.sentence-1)
See also: ISO/IEC 9899:2024, 7.11
Table [103](#tab:setlocale.data.races) — Potential setlocale data races [[tab:setlocale.data.races]](./tab:setlocale.data.races)
| [🔗](#tab:setlocale.data.races-row-1)<br>fprintf | isprint | iswdigit | localeconv | tolower |
| --- | --- | --- | --- | --- |
| [🔗](#tab:setlocale.data.races-row-2)<br>fscanf | ispunct | iswgraph | mblen | toupper |
| [🔗](#tab:setlocale.data.races-row-3)<br>isalnum | isspace | iswlower | mbstowcs | towlower |
| [🔗](#tab:setlocale.data.races-row-4)<br>isalpha | isupper | iswprint | mbtowc | towupper |
| [🔗](#tab:setlocale.data.races-row-5)<br>isblank | iswalnum | iswpunct | setlocale | wcscoll |
| [🔗](#tab:setlocale.data.races-row-6)<br>iscntrl | iswalpha | iswspace | strcoll | wcstod |
| [🔗](#tab:setlocale.data.races-row-7)<br>isdigit | iswblank | iswupper | strerror | wcstombs |
| [🔗](#tab:setlocale.data.races-row-8)<br>isgraph | iswcntrl | iswxdigit | strtod | wcsxfrm |
| [🔗](#tab:setlocale.data.races-row-9)<br>islower | iswctype | isxdigit | strxfrm | wctomb |

102
cppdraft/c/malloc.md Normal file
View File

@@ -0,0 +1,102 @@
[c.malloc]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#c.malloc)
### 20.2.12 C library memory allocation [c.malloc]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2131)
[*Note [1](#note-1)*:
The header [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]") declares the functions described in this subclause[.](#1.sentence-1)
— *end note*]
[🔗](#lib:aligned_alloc)
`void* aligned_alloc(size_t alignment, size_t size);
void* calloc(size_t nmemb, size_t size);
void* malloc(size_t size);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2147)
*Effects*: These functions have the semantics specified in the C standard library[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2151)
*Remarks*: These functions do not attempt to allocate
storage by calling ::operator new() ([[new.delete]](new.delete "17.6.3Storage allocation and deallocation"))[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2157)
These functions implicitly create objects ([[intro.object]](intro.object "6.8.2Object model"))
in the returned region of storage and
return a pointer to a suitable created object[.](#4.sentence-1)
In the case of calloc,
the objects are created before the storage is zeroed[.](#4.sentence-2)
[🔗](#lib:realloc)
`void* realloc(void* ptr, size_t size);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2171)
*Preconditions*: free(ptr) has well-defined behavior[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2175)
*Effects*: If ptr is not null and size is zero,
the behavior is erroneous and the effects are implementation-defined[.](#6.sentence-1)
Otherwise, this function has the semantics specified in the C standard library[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2181)
*Remarks*: This function does not attempt to allocate storage
by calling ::operator new() ([[new.delete]](new.delete "17.6.3Storage allocation and deallocation"))[.](#7.sentence-1)
When a non-null pointer is returned,
this function implicitly creates objects ([[intro.object]](intro.object "6.8.2Object model"))
in the returned region of storage and
returns a pointer to a suitable created object[.](#7.sentence-2)
The objects are created before the storage is copied[.](#7.sentence-3)
[🔗](#lib:free)
`void free(void* ptr);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2198)
*Effects*: This function has the semantics specified in the C standard library[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2202)
*Remarks*: This function does not attempt to
deallocate storage by calling::operator delete()[.](#9.sentence-1)
See also: ISO/IEC 9899:2024, 7.22.3

999
cppdraft/c/math.md Normal file

File diff suppressed because one or more lines are too long

58
cppdraft/c/math/abs.md Normal file
View File

@@ -0,0 +1,58 @@
[c.math.abs]
# 29 Numerics library [[numerics]](./#numerics)
## 29.7 Mathematical functions for floating-point types [[c.math]](c.math#abs)
### 29.7.2 Absolute values [c.math.abs]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9843)
[*Note [1](#note-1)*:
The headers [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]") and[<cmath>](cmath.syn#header:%3ccmath%3e "29.7.1Header <cmath> synopsis[cmath.syn]") declare the functions described in this subclause[.](#1.sentence-1)
— *end note*]
[🔗](#lib:abs)
`constexpr int abs(int j);
constexpr long int abs(long int j);
constexpr long long int abs(long long int j);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9858)
*Effects*: These
functions have the semantics specified in the C standard library
for the functions abs, labs, and llabs, respectively[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9864)
*Remarks*: If abs is called with an argument of type X for which is_unsigned_v<X> is true and
if X cannot be converted to int by [integral promotion](conv.prom "7.3.7Integral promotions[conv.prom]"), the program is ill-formed[.](#3.sentence-1)
[*Note [2](#note-2)*:
Allowing arguments that can be promoted to int provides compatibility with C[.](#3.sentence-2)
— *end note*]
[🔗](#itemdecl:2)
`constexpr floating-point-type abs(floating-point-type x);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9881)
*Returns*: The absolute value of x[.](#4.sentence-1)
See also: ISO/IEC 9899:2024, 7.12.7.2, 7.22.6.1

View File

@@ -0,0 +1,16 @@
[c.math.fpclass]
# 29 Numerics library [[numerics]](./#numerics)
## 29.7 Mathematical functions for floating-point types [[c.math]](c.math#fpclass)
### 29.7.5 Classification / comparison functions [c.math.fpclass]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9936)
The classification / comparison functions behave the same as the C macros with the
corresponding names defined in the C standard library[.](#1.sentence-1)
See also: ISO/IEC 9899:2024, 7.12.3, 7.12.4

19
cppdraft/c/math/hypot3.md Normal file
View File

@@ -0,0 +1,19 @@
[c.math.hypot3]
# 29 Numerics library [[numerics]](./#numerics)
## 29.7 Mathematical functions for floating-point types [[c.math]](c.math#hypot3)
### 29.7.3 Three-dimensional hypotenuse [c.math.hypot3]
[🔗](#lib:hypot,3-argument_form)
`constexpr floating-point-type hypot(floating-point-type x, floating-point-type y,
floating-point-type z);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9897)
*Returns*: √x2+y2+z2[.](#1.sentence-1)

51
cppdraft/c/math/lerp.md Normal file
View File

@@ -0,0 +1,51 @@
[c.math.lerp]
# 29 Numerics library [[numerics]](./#numerics)
## 29.7 Mathematical functions for floating-point types [[c.math]](c.math#lerp)
### 29.7.4 Linear interpolation [c.math.lerp]
[🔗](#lib:lerp)
`constexpr floating-point-type lerp(floating-point-type a, floating-point-type b,
floating-point-type t) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9910)
*Returns*: a+t(b−a)[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9914)
*Remarks*: Let r be the value returned[.](#2.sentence-1)
If isfinite(a) && isfinite(b), then:
- [(2.1)](#2.1)
If t == 0, then r == a[.](#2.1.sentence-1)
- [(2.2)](#2.2)
If t == 1, then r == b[.](#2.2.sentence-1)
- [(2.3)](#2.3)
If t >= 0 && t <= 1, then isfinite(r)[.](#2.3.sentence-1)
- [(2.4)](#2.4)
If isfinite(t) && a == b, then r == a[.](#2.4.sentence-1)
- [(2.5)](#2.5)
If isfinite(t) || !isnan(t) && b - a != 0, then !isnan(r)[.](#2.5.sentence-1)
Let *CMP*(x,y) be 1 if x > y,-1 if x < y, and 0 otherwise[.](#2.sentence-3)
For any t1 and t2, the product of*CMP*(lerp(a, b, t2), lerp(a, b, t1)),*CMP*(t2, t1), and*CMP*(b, a) is non-negative[.](#2.sentence-4)

53
cppdraft/c/math/rand.md Normal file
View File

@@ -0,0 +1,53 @@
[c.math.rand]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#c.math.rand)
### 29.5.10 Low-quality random number generation [c.math.rand]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6923)
[*Note [1](#note-1)*:
The header [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]") declares the functions described in this subclause[.](#1.sentence-1)
— *end note*]
[🔗](#lib:rand)
`int rand();
void srand(unsigned int seed);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6937)
*Effects*: Therand and srand functions have the semantics specified in the C standard library[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6943)
*Remarks*: The implementation
may specify that particular library functions may callrand[.](#3.sentence-1)
It is implementation-defined
whether the rand function
may introduce data races ([[res.on.data.races]](res.on.data.races "16.4.6.10Data race avoidance"))[.](#3.sentence-2)
[*Note [2](#note-2)*:
The other random
number generation facilities in this document ([[rand]](rand "29.5Random number generation")) are often preferable
to rand, because rand's underlying algorithm is unspecified[.](#3.sentence-3)
Use of rand therefore continues to be non-portable, with unpredictable
and oft-questionable quality and performance[.](#3.sentence-4)
— *end note*]
See also: ISO/IEC 9899:2024, 7.22.2

89
cppdraft/c/mb/wcs.md Normal file
View File

@@ -0,0 +1,89 @@
[c.mb.wcs]
# 28 Text processing library [[text]](./#text)
## 28.7 Null-terminated sequence utilities [[text.c.strings]](text.c.strings#c.mb.wcs)
### 28.7.5 Multibyte / wide string and character conversion functions [c.mb.wcs]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L13295)
[*Note [1](#note-1)*:
The headers [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]"),[<cuchar>](cuchar.syn#header:%3ccuchar%3e "28.7.4Header <cuchar> synopsis[cuchar.syn]"),
and [<cwchar>](cwchar.syn#header:%3ccwchar%3e "28.7.3Header <cwchar> synopsis[cwchar.syn]") declare the functions described in this subclause[.](#1.sentence-1)
— *end note*]
[🔗](#lib:mbsinit)
`int mbsinit(const mbstate_t* ps);
int mblen(const char* s, size_t n);
size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n);
size_t wcstombs(char* s, const wchar_t* pwcs, size_t n);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L13315)
*Effects*: These functions have the semantics specified in the C standard library[.](#2.sentence-1)
See also: ISO/IEC 9899:2024, 7.22.7.1, 7.22.8, 7.29.6.2.1
[🔗](#lib:mbtowc)
`int mbtowc(wchar_t* pwc, const char* s, size_t n);
int wctomb(char* s, wchar_t wchar);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L13330)
*Effects*: These functions have the semantics specified in the C standard library[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L13334)
*Remarks*: Calls to these functions
may introduce a data race ([[res.on.data.races]](res.on.data.races "16.4.6.10Data race avoidance"))
with other calls to the same function[.](#4.sentence-1)
See also: ISO/IEC 9899:2024, 7.22.7
[🔗](#itemdecl:3)
`size_t [mbrlen](#lib:mbrlen "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(const char* s, size_t n, mbstate_t* ps);
size_t [mbrtowc](#lib:mbrtowc "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps);
size_t [wcrtomb](#lib:wcrtomb "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char* s, wchar_t wc, mbstate_t* ps);
size_t [mbrtoc8](#lib:mbrtoc8 "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char8_t* pc8, const char* s, size_t n, mbstate_t* ps);
size_t [c8rtomb](#lib:c8rtomb "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char* s, char8_t c8, mbstate_t* ps);
size_t [mbrtoc16](#lib:mbrtoc16 "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
size_t [c16rtomb](#lib:c16rtomb "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char* s, char16_t c16, mbstate_t* ps);
size_t [mbrtoc32](#lib:mbrtoc32 "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
size_t [c32rtomb](#lib:c32rtomb "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char* s, char32_t c32, mbstate_t* ps);
size_t [mbsrtowcs](#lib:mbsrtowcs "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(wchar_t* dst, const char** src, size_t len, mbstate_t* ps);
size_t [wcsrtombs](#lib:wcsrtombs "28.7.5Multibyte / wide string and character conversion functions[c.mb.wcs]")(char* dst, const wchar_t** src, size_t len, mbstate_t* ps);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L13358)
*Effects*: These functions have the semantics specified in the C standard library[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L13362)
*Remarks*: Calling these functions
with an mbstate_t* argument that is a null pointer value
may introduce a data race ([[res.on.data.races]](res.on.data.races "16.4.6.10Data race avoidance"))
with other calls to the same function
with an mbstate_t* argument that is a null pointer value[.](#6.sentence-1)
See also: ISO/IEC 9899:2024, 7.30.1, 7.31.6.3, 7.31.6.4

51
cppdraft/c/strings.md Normal file
View File

@@ -0,0 +1,51 @@
[c.strings]
# 27 Strings library [[strings]](./#strings)
## 27.5 Null-terminated sequence utilities [c.strings]
### [27.5.1](#cstring.syn) Header <cstring> synopsis [[cstring.syn]](cstring.syn)
[🔗](#lib:memchr)
#define __STDC_VERSION_STRING_H__ 202311Lnamespace std {using size_t = *see [[support.types.layout]](support.types.layout "17.2.4Sizes, alignments, and offsets")*; // freestandingvoid* memcpy(void* s1, const void* s2, size_t n); // freestandingvoid* memccpy(void* s1, const void* s2, int c, size_t n); // freestandingvoid* memmove(void* s1, const void* s2, size_t n); // freestandingchar* strcpy(char* s1, const char* s2); // freestandingchar* strncpy(char* s1, const char* s2, size_t n); // freestandingchar* strdup(const char* s); char* strndup(const char* s, size_t size); char* strcat(char* s1, const char* s2); // freestandingchar* strncat(char* s1, const char* s2, size_t n); // freestandingint memcmp(const void* s1, const void* s2, size_t n); // freestandingint strcmp(const char* s1, const char* s2); // freestandingint strcoll(const char* s1, const char* s2); int strncmp(const char* s1, const char* s2, size_t n); // freestanding size_t strxfrm(char* s1, const char* s2, size_t n); const void* memchr(const void* s, int c, size_t n); // freestanding; see [[library.c]](library.c "16.2The C standard library")void* memchr(void* s, int c, size_t n); // freestanding; see [[library.c]](library.c "16.2The C standard library")const char* strchr(const char* s, int c); // freestanding; see [[library.c]](library.c "16.2The C standard library")char* strchr(char* s, int c); // freestanding; see [[library.c]](library.c "16.2The C standard library") size_t strcspn(const char* s1, const char* s2); // freestandingconst char* strpbrk(const char* s1, const char* s2); // freestanding; see [[library.c]](library.c "16.2The C standard library")char* strpbrk(char* s1, const char* s2); // freestanding; see [[library.c]](library.c "16.2The C standard library")const char* strrchr(const char* s, int c); // freestanding; see [[library.c]](library.c "16.2The C standard library")char* strrchr(char* s, int c); // freestanding; see [[library.c]](library.c "16.2The C standard library") size_t strspn(const char* s1, const char* s2); // freestandingconst char* strstr(const char* s1, const char* s2); // freestanding; see [[library.c]](library.c "16.2The C standard library")char* strstr(char* s1, const char* s2); // freestanding; see [[library.c]](library.c "16.2The C standard library")char* strtok(char* s1, const char* s2); void* memset(void* s, int c, size_t n); // freestandingvoid* memset_explicit(void* s, int c, size_t n); // freestandingchar* strerror(int errnum);
size_t strlen(const char* s); // freestanding}#define NULL *see [[support.types.nullptr]](support.types.nullptr "17.2.3Null pointers")* // freestanding
[1](#cstring.syn-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L5526)
The contents and meaning of the header <cstring> are the same as the C standard library header [<string.h>](support.c.headers.general#header:%3cstring.h%3e "17.15.1General[support.c.headers.general]")[.](#cstring.syn-1.sentence-1)
[2](#cstring.syn-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L5530)
The functions strerror and strtok are not required to[avoid data races](res.on.data.races "16.4.6.10Data race avoidance[res.on.data.races]")[.](#cstring.syn-2.sentence-1)
[3](#cstring.syn-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L5534)
The functions memcpy and memmove are [signal-safe](support.signal#def:evaluation,signal-safe "17.14.5Signal handlers[support.signal]")[.](#cstring.syn-3.sentence-1)
Each of these functions implicitly creates objects ([[intro.object]](intro.object "6.8.2Object model"))
in the destination region of storage
immediately prior to copying the sequence of characters to the destination[.](#cstring.syn-3.sentence-2)
Each of these functions returns a pointer to a suitable created object, if any,
otherwise the value of the first parameter[.](#cstring.syn-3.sentence-3)
[4](#cstring.syn-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L5544)
[*Note [1](#cstring.syn-note-1)*:
The functionsstrchr, strpbrk, strrchr, strstr, and memchr,
have different signatures in this document,
but they have the same behavior as in the [C standard library](library.c "16.2The C standard library[library.c]")[.](#cstring.syn-4.sentence-1)
— *end note*]
See also: ISO/IEC 9899:2024, 7.26