my-server
← Wiki

C23 (C standard revision)

C23, formally ISO/IEC 9899:2024, is the current open standard for the C programming language, which supersedes C17 (standard ISO/IEC 9899:2018). It was started in 2016 informally as C2x, and was published on October 31, 2024. The freely available draft most similar to the one published is document N3220 (see Available texts, below). The first WG14 meeting for the C2x draft was held in October 2019, virtual remote meetings were held in 2020 due to the COVID-19 pandemic, then various teleconference meetings continued to occur through 2024.

In C23, the value of <code>__STDC_VERSION__</code> changes from <code>201710L</code> to <code>202311L</code>. The common names "C17" and "C23" reflect these values, which are frozen prior to final adoption, rather than the years in the ISO standards identifiers (9899:2018 and 9899:2024).

Features

Changes integrated into the latest working draft of C23 are listed below.

Constants

  • Add constant for <code>nullptr_t</code> type.
  • Add <code>'</code> digit separator to literal constants, such as (equating to 0xFEDCBA98), (equating to 299792458), (equating to 1.414213562).
  • Add <code>0b</code> and <code>0B</code> binary literal constant prefixes, such as (equating to 0xAA), and was previously added in the C++14 standard. This change is similar to earlier established <code>0x</code> and <code>0X</code> hexadecimal prefixes.
  • Add <code>wb</code> and <code>uwb</code> integer literal suffixes for and types, such as yields an <code>unsigned _BitInt(3)</code>, and yields a <code>signed _BitInt(4)</code> which has three value bits and one sign bit.
  • Add the ability to specify the underlying type of an <code>enum</code>.
  • Allow with no fixed underlying type to store values that are not representable by .

Keywords

  • Add and keywords.
  • Add , , , , keywords. Previously defined keywords become alternative spellings: , , , , .
  • Add keyword (see "types" group).
  • Add and keywords (see "types" group).
  • Add keyword (see "constants" group).
  • Add keyword (see "other" group).
  • Add , , keywords for (optional) decimal floating-point arithmetic (see "other" group).

Types

  • Add , a null pointer type.
  • Add and types for bit-precise integers. Add macro for maximum bit width.
  • Add <code>ckd_add()</code>, <code>ckd_sub()</code>, <code>ckd_mul()</code> macros for checked integer operations.
  • Variably-modified types (but not VLAs which are automatic variables allocated on the stack) become a mandatory feature.
  • Better support for using <code>const</code> with arrays.
  • Standardization of the <code>typeof(...)</code> operator.
  • The meaning of the keyword was changed to cause type inference while also retaining its old meaning of a storage class specifier if used alongside a type. Unlike C++, C23 allows type inference only for object definitions (no inferring function return type or function parameter type).
  • Compatibility rules for structure, union, and enumerated types were changed to allow a redeclaration of a compatible type with the same tag.
  • Exact-width integer may now exceed (N2888).
  • Specify that <code>[u]intN_t</code> when defined must designate the same type as <code>[u]int_leastN_t</code>

Syntax

  • Labels can appear before declarations and at the end of compound statements.
  • Unnamed parameters in function definitions.
  • Zero initialization with <code>{}</code> (including initialization of VLAs).
  • Variadic functions no longer need a named argument before the ellipsis and the macro no longer needs a second argument nor does it evaluate any argument after the first one if present.
  • Add C++11 style attribute syntax using double square brackets . In addition to C++11 attributes listed below, add new attributes:
  • <code><nowiki>unsequenced</nowiki></code> allows compiler optimizations for functions producing repeatable outputs only based on their parameters
  • <code><nowiki>reproducible</nowiki></code>, similar to <code><nowiki>unsequenced</nowiki></code>, but for functions whose call order also matters
  • Add single-argument <code>static_assert</code> for compatibility with C++17.
  • Functions with no arguments listed in the prototype (e.g. <code>void foo()</code>) are understood as taking no arguments (see removal of K&R function declarations)

Preprocessor

  • Add and directives, which are essentially equivalent to and . Both directives were added to standard and GCC 12.
  • Add directive for binary resource inclusion and allowing the availability of a resource to be checked by preprocessor directives.
  • Add directive for diagnostics.
  • Add allowing the availability of a header to be checked by preprocessor directives.
  • Add allowing the availability of an attribute to be checked by preprocessor directives. (see " compatibility" group for new attribute feature)
  • Add functional macro for variadic macros which expands to its argument only if a variadic argument has been passed to the containing macro.

C++ compatibility

  • Various syntax changes improve compatibility with C++, such as labels before declarations, unnamed function arguments, zero initialization with <code>{}</code>, variadic functions without named argument, C++11 style attributes, <code>_Static_assert</code> (see Syntax). For labels at the end of compound statements a corresponding change was made to C++23.
  • Add C++-style attributes (see Syntax). Add attributes , , , , and attribute for compatibility with C++11, then deprecate , , header <code><stdnoreturn.h></code> features introduced in C11. Duplicate attributes are allowed for compatibility with C++23. All standard attributes can also be surrounded by double underscores (e.g. is equivalent to ).
  • Add <code>u8</code> prefix for character literals to represent UTF-8 encoding for compatibility with C++17.
  • Add and preprocessing directives for compatibility with C++23. (see "preprocessor" group)

Other

  • Support for the ISO/IEC 60559:2020, the current version of the IEEE 754 standard for floating-point arithmetic, with extended binary floating-point arithmetic and (optional) decimal floating-point arithmetic.
  • The <code>constexpr</code> specifier for objects but not functions, unlike C++'s equivalent.
  • Add type for storing UTF-8 encoded data and change the type of u8 character constants and string literals to . Also, the functions <code>mbrtoc8()</code> and <code>c8rtomb()</code> to convert a narrow multibyte character to UTF-8 encoding and a single code point from UTF-8 to a narrow multibyte character representation respectively.
  • Clarify that all strings and literals shall be UTF-16 encoded, and all strings and literals shall be UTF-32 encoded, unless otherwise explicitly specified.
  • Allow storage class specifiers to appear in compound literal definition.

Standard Library

Existing functions

  • Add <code>%b</code> binary conversion specifier to <code>printf()</code> function family.
  • Add <code>%b</code> binary conversion specifier to <code>scanf()</code> function family.
  • Add <code>0b</code> and <code>0B</code> binary conversion support to functions <code>strtol()</code>, <code>strtoll()</code>, <code>strtoul()</code>, <code>strtoull()</code>, and their wide counterparts <code>wcstol()</code>, <code>wcstoll()</code>, <code>wcstoul()</code>, <code>wcstoull()</code>. If a sign is present, the <code>0b</code> or <code>0B</code> follows the sign.
  • Add specific width modifiers <code>%wN</code> and <code>%wfN</code> to <code>printf()</code> function family.
  • Add specific width modifiers <code>%wN</code> and <code>%wfN</code> to scanf<code>()</code> function family.
  • Make the functions <code>bsearch()</code>, <code>bsearch_s()</code>, <code>memchr()</code>, <code>strchr()</code>, <code>strpbrk()</code>, <code>strrchr()</code>, <code>strstr()</code>, and their wide counterparts <code>wmemchr()</code>, <code>wcschr()</code>, <code>wcspbrk()</code>, <code>wcsrchr()</code>, <code>wcsstr()</code> return a const qualified object if one was passed to them.

New functions

  • Add <code>memset_explicit()</code> function in <code><string.h></code> to erase sensitive data, where memory store must always be performed regardless of optimizations.
  • Add <code>memccpy()</code> function in <code><string.h></code> to efficiently concatenate strings – similar to POSIX and SVID C extensions.
  • Add <code>strdup()</code> and <code>strndup()</code> functions in <code><string.h></code> to allocate a copy of a string – similar to POSIX and SVID C extensions.
  • Add <code>memalignment()</code> function in <code><stdlib.h></code> to determine the byte alignment of a pointer.
  • Add <code>free_sized()</code> and <code>free_aligned_sized()</code> functions in <code><stdlib.h></code> to free memory more efficiently when the size is known.
  • Add bit utility functions / macros / types in new header <code><stdbit.h></code> to examine many integer types. All start with <code>stdc_</code> to minimize conflict with legacy code and 3rd party libraries.
  • In the following, replace <code>*</code> with <code>uc</code>, <code>us</code>, <code>ui</code>, <code>ul</code>, <code>ull</code> for five function names, or blank for a type-generic macro.
  • Add <code>stdc_count_ones_*()</code> and <code>stdc_count_zeros_*()</code> to count number of 1 or 0 bits in value.
  • Add <code>stdc_leading_ones_*()</code> and <code>stdc_leading_zeros_*()</code> to count leading 1 or 0 bits in value.
  • Add <code>stdc_trailing_ones_*()</code> and <code>stdc_trailing_zeros_*()</code> to count trailing 1 or 0 bits in value.
  • Add <code>stdc_first_leading_one_*()</code> and <code>stdc_first_leading_zero_*()</code> to find first leading bit with 1 or 0 in value.
  • Add <code>stdc_first_trailing_one_*()</code> and <code>stdc_first_trailing_zero_*()</code> to find first trailing bit with 1 or 0 in value.
  • Add <code>stdc_has_single_bit_*()</code> to determine if value is an exact power of 2 (return true if and only if there is a single 1 bit).
  • Add <code>stdc_bit_floor_*()</code> to determine the largest integral power of 2 that is not greater than value.
  • Add <code>stdc_bit_ceil_*()</code> to determine the smallest integral power of 2 that is not less than value.
  • Add <code>stdc_bit_width_*()</code> to determine number of bits to represent a value.
  • Add <code>timegm()</code> function in <code><time.h></code> to convert time structure into calendar time value - similar to function in glibc and musl libraries.
  • New <code><math.h></code> functions based on IEEE 754-2019 recommendations, such as trigonometry functions operating on units of and <code>exp10</code>.

Obsolete features

Obsolete C programming language features removed or deprecated from C23:

  • Remove trigraphs.
  • Remove K&R function definitions/declarations (with no information about the function arguments).
  • Remove representations for signed integers other than two's complement. Two's complement signed integer representation will be required.
  • The macros in <code><float.h></code> are obsolescent features.

Compiler support

The following compilers implement an experimental compiler flag to support this standard:

Additionally, versions of GCC beyond GCC 15 now use C23 by default.

Available texts

Like other editions of the C standard, the official ISO text of the standard is not freely available.

The latest working draft pre-C23 that was made public was N3096, dated 2023-04-01. In the months that followed this draft, hundreds of changes were made before producing the working draft N3149 dated 2023-07-09 and the official draft standard N3219 dated 2024-02-22. Neither of these later drafts is public.

On the same date that the draft standard N3219 was announced, a new working draft N3220 was made public. While this document is officially described as a draft of the future version "C2Y" of the standard, the accompanying "Editor's Report" specifies that N3220 differs from the draft C23 standard N3219 only by a fix to one footnote in Annex K.

See also

References

Further reading

  • ISO/IEC 9899:2024 (official C23 standard); ISO; 2024. (available but not free)
  • N3096 (last freely-available working draft before C23); WG14; April 2023. (free download)
  • N3149 (working draft of C23 standard); WG14; July 2023. (not available to public)
  • N3219 (ISO/IEC 9899:2023 DIS Draft); WG14; February 2024. (ISO draft available but not free)
  • N3220 (first working draft after C23; differs from draft standard N3219 only in one footnote); WG14; February 2024. (free download)

External links

* WG14 Document Repository
* WG14 Meetings - agenda and minutes
* WG14 Charters: C2x Charter, C23 Charter, Interpreting the C23 Charter, C Standard Charter