Strings

Overview

A C-style string is a contiguous sequence of characters terminated by the NUL character (refer to ASCII). Text data is considered more platform-independent than binary data since it is unaffected by word size or byte ordering.

Strings can embed escape sequences, denoted with a backslash (\), used to represent characters:

Multibyte Strings

A multibyte string is a C-style string composed of multibyte characters. A multibyte character is a character that may require more than one byte to represent.

Multibyte characters are represented with type char. Multibyte strings are represented with type char*.

UTF-8

A UTF-8 string literal is prefixed with u8. Since C23, a UTF-8 character literal is denoted in the same way.

Wide Character Strings

A wide character is a single value that can uniquely represent all code points of the largest extended character set specified among the supported locales. A wide character string is a NUL-terminated array of wide characters.

Wide characters are represented with type wchar_t. Wide character strings are represented with type wchar_t*.

UTF-16

If the __STDC_UTF_16__ macro is set to 1, then char16_t strings are UTF-16 encoded. Character and string literals of type char16_t are denoted with a u prefix. Since C23, this macro must be set to 1.

UTF-32

If the __STDC_UTF_32__ macro is set to 1, then char32_t strings are UTF-32 encoded. Character and string literals of type char32_t are denoted with a U prefix. Since C23, this macro must be set to 1.

Copying

The two primary functions used for copying memory are memcpy and memmove:

void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
void* memmove(void* s1, const void* s2, size_t n);
Powered by Forestry.md