Top Qs
Timeline
Chat
Perspective
C23 (C standard revision)
C programming language standard, current revision From Wikipedia, the free encyclopedia
Remove ads
C23, formally ISO/IEC 9899:2024, is the current open standard for the C programming language, which supersedes C17 (standard ISO/IEC 9899:2018).[1] It was started in 2016 informally as C2x,[2] and was published on October 31, 2024.[3] The freely available draft most similar to the one published is document N3220[4] (see Available texts, below). The first WG14 meeting for the C2x draft was held in October 2019,[5] 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 (9899:2018 and 9899:2024).
Remove ads
Features
Summarize
Perspective
Changes integrated into the latest working draft of C23 are listed below.[6]
Standard Library
New functions
- Add
memset_explicit()function in<string.h>to erase sensitive data, where memory store must always be performed regardless of optimizations.[7] - Add
memccpy()function in<string.h>to efficiently concatenate strings – similar to POSIX and SVID C extensions.[8] - Add
strdup()andstrndup()functions in<string.h>to allocate a copy of a string – similar to POSIX and SVID C extensions.[9] - Add
memalignment()function in<stdlib.h>to determine the byte alignment of a pointer.[10] - Add bit utility functions / macros / types in new header
<stdbit.h>to examine many integer types. All start withstdc_to minimize conflict with legacy code and 3rd party libraries.[11]- In the following, replace
*withuc,us,ui,ul,ullfor five function names, or blank for a type-generic macro.[11] - Add
stdc_count_ones_*()andstdc_count_zeros_*()to count number of 1 or 0 bits in value.[11] - Add
stdc_leading_ones_*()andstdc_leading_zeros_*()to count leading 1 or 0 bits in value.[11] - Add
stdc_trailing_ones_*()andstdc_trailing_zeros_*()to count trailing 1 or 0 bits in value.[11] - Add
stdc_first_leading_one_*()andstdc_first_leading_zero_*()to find first leading bit with 1 or 0 in value.[11] - Add
stdc_first_trailing_one_*()andstdc_first_trailing_zero_*()to find first trailing bit with 1 or 0 in value.[11] - Add
stdc_has_single_bit_*()to determine if value is an exact power of 2 (return true if and only if there is a single 1 bit).[11] - Add
stdc_bit_floor_*()to determine the largest integral power of 2 that is not greater than value.[11] - Add
stdc_bit_ceil_*()to determine the smallest integral power of 2 that is not less than value.[11] - Add
stdc_bit_width_*()to determine number of bits to represent a value.[11]
- In the following, replace
- Add
timegm()function in<time.h>to convert time structure into calendar time value - similar to function in glibc and musl libraries.[12] - New
<math.h>functions based on IEEE 754-2019 recommendations, such as trigonometry functions operating on units of andexp10.[13]
Existing functions
- Add
%bbinary conversion specifier toprintf()function family.[14] - Add
%bbinary conversion specifier toscanf()function family.[14] - Add
0band0Bbinary conversion support tostrtol()andwcstol()function families.[14] - Make the functions
bsearch(),bsearch_s(),memchr(),strchr(),strpbrk(),strrchr(),strstr(), and their wide counterpartswmemchr(),wcschr(),wcspbrk(),wcsrchr(),wcsstr()return a const qualified object if one was passed to them.[15]
Preprocessor
- Add
#elifdefand#elifndefdirectives,[16] which are essentially equivalent to#elif definedand#elif !defined. Both directives were added to C++23 standard and GCC 12.[17] - Add
#embeddirective for binary resource inclusion and__has_embedallowing the availability of a resource to be checked by preprocessor directives.[18] - Add
#warningdirective for diagnostics.[19] - Add
__has_includeallowing the availability of a header to be checked by preprocessor directives.[20] - Add
__has_c_attributeallowing the availability of an attribute to be checked by preprocessor directives.[21] (see "C++ compatibility" group for new attribute feature) - Add
__VA_OPT__functional macro for variadic macros which expands to its argument only if a variadic argument has been passed to the containing macro.[22]
Types
- Add
nullptr_t, a null pointer type.[23] - Add
_BitInt(N)andunsigned _BitInt(N)types for bit-precise integers. AddBITINT_MAXWIDTHmacro for maximum bit width.[24][25] - Add
ckd_add(),ckd_sub(),ckd_mul()macros for checked integer operations.[26] - Variably-modified types (but not VLAs which are automatic variables allocated on the stack) become a mandatory feature.[27]
- Better support for using
constwith arrays.[28] - Standardization of the
typeof(...)operator.[29] - The meaning of the
autokeyword 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).[30] - Compatibility rules for structure, union, and enumerated types were changed to allow a redeclaration of a compatible type with the same tag.[31]
- Exact-width integer may now exceed
intmax_t(N2888).[32]
Constants
- Add
nullptrconstant fornullptr_ttype.[23] - Add
wbanduwbinteger literal suffixes for_BitInt(N)andunsigned _BitInt(N)types,[33] such as6uwbyields anunsigned _BitInt(3), and-6wbyields asigned _BitInt(4)which has three value bits and one sign bit. - Add
0band0Bbinary literal constant prefixes,[34] such as0b10101010(equating to 0xAA). - Add
'digit separator to literal constants,[35] such as0xFE'DC'BA'98(equating to 0xFEDCBA98),299'792'458(equating to 299792458),1.414'213'562(equating to 1.414213562). - Add the ability to specify the underlying type of an
enum.[36] - Allow
enums with no fixed underlying type to store values that are not representable byint.[37]
Keywords
- Add
trueandfalsekeywords.[38] - Add
alignas,alignof,bool,static_assert,thread_localkeywords. Previously defined keywords become alternative spellings:_Alignas,_Alignof,_Bool,_Static_assert,_Thread_local.[39] - Add
_BitIntkeyword (see "types" group) - Add
typeofandtypeof_unqualkeywords (see "types" group) - Add
nullptrkeyword (see "constants" group) - Add
constexprkeyword (see "other" group) - Add
_Decimal32,_Decimal64,_Decimal128keywords for (optional) decimal floating-point arithmetic (see "other" group)
Syntax
- Labels can appear before declarations and at the end of compound statements.[40]
- Unnamed parameters in function definitions.[41]
- Zero initialization with
{}(including initialization of VLAs).[42] - Variadic functions no longer need a named argument before the ellipsis and the
va_startmacro no longer needs a second argument nor does it evaluate any argument after the first one if present.[43] - Add C++11 style attribute syntax[44] using double square brackets
[[]]. In addition to C++11 attributes listed below, add new attributes: - Add single-argument
_Static_assertfor compatibility with C++17.[46] - Functions with no arguments listed in the prototype (e.g.
void foo()) are understood as taking no arguments (see removal of K&R function declarations)
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(see Syntax). For labels at the end of compound statements a corresponding change was made to C++23.[47] - Add C++-style attributes (see Syntax). Add attributes[48]
[[deprecated]],[49][[fallthrough]],[50][[maybe_unused]],[51][[nodiscard]],[52] and[[noreturn]]attribute for compatibility with C++11, then deprecate_Noreturn,noreturn, header<stdnoreturn.h>features introduced in C11.[53] Duplicate attributes are allowed for compatibility with C++23.[54] All standard attributes can also be surrounded by double underscores (e.g.[[__deprecated__]]is equivalent to[[deprecated]]). - Add
u8prefix for character literals to represent UTF-8 encoding for compatibility with C++17.[55][56] - Add
#elifdefand#elifndefpreprocessing directives for compatibility with C++23.[16] (see "preprocessor" group)
Other features
- 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.[57][58]
- The
constexprspecifier for objects but not functions, unlike C++'s equivalent.[59] - Add
char8_ttype for storing UTF-8 encoded data and change the type of u8 character constants and string literals tochar8_t. Also, the functionsmbrtoc8()andc8rtomb()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.[60] - Clarify that all
char16_tstrings and literals shall be UTF-16 encoded, and allchar32_tstrings and literals shall be UTF-32 encoded, unless otherwise explicitly specified.[61] - Allow storage class specifiers to appear in compound literal definition.[62]
Remove ads
Obsolete features
Some old obsolete features are either removed or deprecated from the working draft of C23:
- Remove trigraphs.[63]
- Remove K&R function definitions/declarations (with no information about the function arguments).[64][65]
- Remove representations for signed integers other than two's complement. Two's complement signed integer representation will be required.[66]
- The
*_HAS_SUBNORMmacros in<float.h>are obsolescent features.[67]
Remove ads
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.[71]
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,[6] dated 2023-04-01. In the months that followed this draft, hundreds of changes[72] were made before producing the working draft N3149 dated 2023-07-09 and the official draft standard N3219 dated 2024-02-22.[72][73] Neither of these later drafts are public.[72][73]
On the same date that the draft standard N3219 was announced, a new working draft N3220[4] was made public. While this document is officially described[73] 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.[73]
Remove ads
See also
References
Further reading
External links
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads