C23 (C standard revision)
C23, formally ISO/IEC 9899:2024, is the current open standard for the C programming language, which supersedes C17. 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. 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
__STDC_VERSION__ changes from 201710L to 202311L. 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.Features
Changes integrated into the latest working draft of C23 are listed below.Constants
- Add nullptr| constant for
nullptr_ttype. - Add
'digit separator to literal constants, such as , , . - Add
0band0Bbinary literal constant prefixes, such as , and was previously added in the C++14 standard. This change is similar to earlier established0xand0Xhexadecimal prefixes. - Add
wbanduwbinteger literal suffixes for and types, such as yields anunsigned _BitInt, and yields asigned _BitIntwhich has three value bits and one sign bit. - Add the ability to specify the underlying type of an
enum. - Allow with no fixed underlying type to store values that are not representable by.
Keywords
- Add and keywords.
- Add,,,, thread-local storage| keywords. Previously defined keywords become alternative spellings:,,,,.
- Add keyword.
- Add and keywords.
- Add keyword.
- Add keyword.
- Add,, keywords for decimal floating-point arithmetic.
Types
- Add nullptr_t|, a null pointer type.
- Add and types for bit-precise integers. Add macro for maximum bit width.
- Add
ckd_add,ckd_sub,ckd_mulmacros for checked integer operations. - Variably-modified types become a mandatory feature.
- Better support for using
constwith arrays. - Standardization of the
typeofoperator. - 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.
- 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 .
- Specify that
intN_twhen defined must designate the same type asint_leastN_tSyntax
- Labels can appear before declarations and at the end of compound statements.
- Unnamed parameters in function definitions.
- Zero initialization with
. - 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:
- *
allows compiler optimizations for functions producing repeatable outputs only based on their parametersunsequenced - *
, similar toreproducible , but for functions whose call order also mattersunsequenced - Add single-argument
static_assertfor compatibility with C++17. - Functions with no arguments listed in the prototype are understood as taking no arguments
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.
- 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
, variadic functions without named argument, C++11 style attributes,_Static_assert. For labels at the end of compound statements a corresponding change was made to C++23. - Add C++-style attributes. Add attributes,,,, and attribute for compatibility with C++11, then deprecate,, header
features introduced in C11. Duplicate attributes are allowed for compatibility with C++23. All standard attributes can also be surrounded by double underscores. - Add
u8prefix for character literals to represent UTF-8 encoding for compatibility with C++17. - Add and preprocessing directives for compatibility with C++23.
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 decimal floating-point arithmetic.
- The
constexprspecifier 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
mbrtoc8andc8rtombto 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
%bbinary conversion specifier toprintffunction family. - Add
%bbinary conversion specifier toscanffunction family. - Add
0band0Bbinary conversion support to functionsstrtol,strtoll,strtoul,strtoull, and their wide counterpartswcstol,wcstoll,wcstoul,wcstoull. If a sign is present, the0bor0Bfollows the sign. - Add specific width modifiers
%wNand%wfNtoprintffunction family. - Add specific width modifiers
%wNand%wfNto scanffunction family. - Make the functions
bsearch,bsearch_s,memchr,strchr,strpbrk,strrchr,strstr, and their wide counterpartswmemchr,wcschr,wcspbrk,wcsrchr,wcsstrreturn a const qualified object if one was passed to them.New functions
- Add
memset_explicitfunction into erase sensitive data, where memory store must always be performed regardless of optimizations. - Add
memccpyfunction into efficiently concatenate strings – similar to POSIX and SVID C extensions. - Add
strdupandstrndupfunctions into allocate a copy of a string – similar to POSIX and SVID C extensions. - Add
memalignmentfunction into determine the byte alignment of a pointer. - Add bit utility functions / macros / types in new header
to examine many integer types. All start withstdc_to minimize conflict with legacy code and 3rd party libraries. - * In the following, replace
*withuc,us,ui,ul,ullfor five function names, or blank for a type-generic macro. - * Add
stdc_count_ones_*andstdc_count_zeros_*to count number of 1 or 0 bits in value. - * Add
stdc_leading_ones_*andstdc_leading_zeros_*to count leading 1 or 0 bits in value. - * Add
stdc_trailing_ones_*andstdc_trailing_zeros_*to count trailing 1 or 0 bits in value. - * Add
stdc_first_leading_one_*andstdc_first_leading_zero_*to find first leading bit with 1 or 0 in value. - * Add
stdc_first_trailing_one_*andstdc_first_trailing_zero_*to find first trailing bit with 1 or 0 in value. - * Add
stdc_has_single_bit_*to determine if value is an exact power of 2. - * Add
stdc_bit_floor_*to determine the largest integral power of 2 that is not greater than value. - * Add
stdc_bit_ceil_*to determine the smallest integral power of 2 that is not less than value. - * Add
stdc_bit_width_*to determine number of bits to represent a value. - Add
timegmfunction into convert time structure into calendar time value - similar to function in glibc and musl libraries. - New
functions based on IEEE 754-2019 recommendations, such as trigonometry functions operating on units of andexp10.Obsolete features
- Remove trigraphs.
- Remove K&R function definitions/declarations.
- Remove representations for signed integers other than two's complement. Two's complement signed integer representation will be required.
- The macros in
are obsolescent features.