C23 (C standard revision)
C23 is the informal name for what will likely become ISO/IEC 9899:2024, the next standard for the C programming language, which will replace C17 (standard ISO/IEC 9899:2018).[1] It was started in 2016 informally as C2x,[2] and expected to be published in 2024.[3] The most recent publicly available working draft of C23 was released on April 1, 2023.[4] 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 2023.
C language revisions |
---|
Features
Changes integrated into the latest working draft of C23 are listed below.[4]
New functions
- add
memset_explicit()
function in<string.h>
to erase sensitive data, where memory store must always be performed regardless of optimizations.[6] - add
memccpy()
function in<string.h>
to efficiently concatenate strings – similar to POSIX and SVID C extensions.[7] - add
strdup()
andstrndup()
functions in<string.h>
to allocate a copy of a string – similar to POSIX and SVID C extensions.[8] - add
memalignment()
function in<stdlib.h>
to determine the byte alignment of a pointer.[9] - 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.[10]- In the following, replace
*
withuc
,us
,ui
,ul
,ull
for five function names, or blank for a type-generic macro.[10] - add
stdc_count_ones*()
andstdc_count_zeros*()
to count number of 1 or 0 bits in value.[10] - add
stdc_leading_ones*()
andstdc_leading_zeros*()
to count leading 1 or 0 bits in value.[10] - add
stdc_trailing_ones*()
andstdc_trailing_zeros*()
to count trailing 1 or 0 bits in value.[10] - add
stdc_first_leading_one*()
andstdc_first_leading_zero*()
to find first leading bit with 1 or 0 in value.[10] - add
stdc_first_trailing_one*()
andstdc_first_trailing_zero*()
to find first trailing bit with 1 or 0 in value.[10] - add
stdc_has_single_bit*()
to determine if value an exact power of 2 (return true if and only if there is a single 1 bit).[10] - add
stdc_bit_floor*()
to determine the largest integral power of 2 that is not greater than value.[10] - add
stdc_bit_ceil*()
to determine the smallest integral power of 2 that is not less than value.[10] - add
stdc_bit_width*()
to determine number of bits to represent a value.[10]
- 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.[11]
Existing functions
- add
%b
binary conversion specifier toprintf()
function family, prepending non-zero values with0b
, similar to how%x
works. Implementations that previously didn't use%B
as their own extension are encouraged to implement and prepend non-zero values with0B
, similar to how%X
works.[12] - add
%b
binary conversion specifier toscanf()
function family.[12] - add
0b
and0B
binary conversion support tostrtol()
andwcstol()
function families.[12] - 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.[13]
Preprocessor
- add
#elifdef
and#elifndef
directives[14] are essentially equivalent to#elif defined
and#elif !defined
. Both directives were added to C++23 standard and GCC 12.[15] - add
#embed
directive for binary resource inclusion and__has_embed
allowing the availability of a resource to be checked by preprocessor directives.[16] - add
#warning
directive for diagnostics.[17] - add
__has_include
allowing the availability of a header to be checked by preprocessor directives.[18] - add
__has_c_attribute
allowing the availability of an attribute to be checked by preprocessor directives.[19] (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.[20]
Types
- add
nullptr_t
, a null pointer type.[21] - add
_BitInt(N)
andunsigned _BitInt(N)
types for bit-precise integers. AddBITINT_MAXWIDTH
macro for maximum bit width.[22][23] Addckd_add()
,ckd_sub()
,ckd_mul()
macros for checked integer operations.[24] - Variably-modified types (but not VLAs which are automatic variables allocated on the stack) become a mandatory feature.[25]
- Better support for using
const
with arrays.[26] - Standardization of the
typeof(...)
operator.[27] - the meaning of the
auto
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).[28] - compatibility rules for structure, union, and enumerated types were changed to allow a redeclaration of a compatible type with the same tag.[29]
Constants
- add
nullptr
constant fornullptr_t
type.[21] - add
wb
anduwb
integer literal suffixes for_BitInt(N)
andunsigned _BitInt(N)
types,[30] such as6uwb
yields anunsigned _BitInt(3)
, and-6wb
yields asigned _BitInt(4)
which has three value bits and one sign bit. - add
0b
and0B
binary literal constant prefixes,[31] such as0b10101010
(equating to 0xAA). - add
'
digit separator to literal constants,[32] 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
.[33] - allow
enum
s with no fixed underlying type to store values that aren't representable byint
.[34]
Keywords
- add
true
andfalse
keywords.[35] - add
alignas
,alignof
,bool
,static_assert
,thread_local
keywords. Previously defined keywords become alternative spellings:_Alignas
,_Alignof
,_Bool
,_Static_assert
,_Thread_local
.[36] - add
_BitInt
keyword (see "types" group) - add
typeof
andtypeof_unqual
keywords (see "types" group) - add
nullptr
keyword (see "constants" group) - add
constexpr
keyword (see "other" group) - add
_Decimal32
,_Decimal64
,_Decimal128
keywords for (optional) decimal floating-point arithmetic (see "other" group)
Syntax
- Labels can appear before declarations and at the end of compound statements.[37]
- Unnamed parameters in function definitions.[38]
- Zero initialization with
{}
(including initialization of VLAs).[39] - variadic functions no longer need a named argument before the ellipsis and the
va_start
macro no longer needs a second argument nor does it evaluate any argument after the first one if present.[40] - add C++11 style attribute syntax[41] using double square brackets
[[]]
. - add single-argument
_Static_assert
for compatibility with C++17.[42] - functions with no arguments listed in the prototype
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.[43] - add C++-style attributes (see Syntax). Add attributes [44]
[[deprecated]]
,[45][[fallthrough]]
,[46][[maybe_unused]]
,[47][[nodiscard]]
,[48] and[[noreturn]]
attribute for compatibility with C++11, then deprecate_Noreturn
,noreturn
, header<stdnoreturn.h>
features introduced in C11.[49] Duplicate attributes are allowed for compatibility with C++23.[50] All standard attributes can also be surrounded by double underscores (e.g[[__deprecated__]]
is equivalent to[[deprecated]]
). - add
u8
prefix for character literals to represent UTF-8 encoding for compatibility with C++17.[51][52] - add
#elifdef
and#elifndef
preprocessing directives for compatibility with C++23.[14] (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.[53][54]
- The
constexpr
specifier for objects but not functions, unlike C++'s equivalent.[55] - add
char8_t
type 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.[56] - clarify that all
char16_t
strings and literals shall be UTF-16 encoded, and allchar32_t
strings and literals shall be UTF-32 encoded, unless otherwise explicitly specified.[57] - allow storage class specifiers to appear in compound literal definition.[58]
Obsolete features
Some old obsolete features are either removed or deprecated from the working draft of C23:
- Remove Trigraphs.[59]
- Remove K&R function definitions/declarations (with no information about the function arguments).[60][61]
- Remove representations for signed integers other than two's complement. Two's complement signed integer representation will be required.[62]
- The
*_HAS_SUBNORM
macros in<float.h>
are obsolescent features.[63]
Compiler support
The GCC 9,[64] Clang 9.0,[65] and Pelles C 11.00[66] compilers implement an experimental compiler flag to support this standard.
See also
References
- "History of C". cppreference.com. 2022-06-27. Archived from the original on October 19, 2022.
- "WG14-N2086 : C2x Charter". open-std.org. 2016-09-20. Archived from the original on December 22, 2022.
- "WG14-N3132 : Revised C23 Schedule" (PDF). open-std.org. 2023-06-04. Archived (PDF) from the original on June 9, 2023.
- "WG14-N3096 : Draft for ISO/IEC 9899:2023" (PDF). open-std.org. April 1, 2023. Archived (PDF) from the original on April 2, 2023.
- "WG14-N2437 : Agenda for October 2019". open-std.org. 2019-10-21. Archived from the original on March 5, 2021.
- "WG14-N2897 : memset_explicit()". open-std.org. 2021-12-27. Archived from the original on October 25, 2022.
- "WG14-N2349 : Toward more efficient string copying and concatenation". open-std.org. 2019-03-18. Archived from the original on September 30, 2022.
- "WG14-N2353 : strdup() and strndup()". open-std.org. 2019-03-18. Archived from the original on December 24, 2022.
- "WG14-N2974 : Queryable pointer alignment" (PDF). open-std.org. 2022-04-15. Archived (PDF) from the original on October 13, 2022.
- "WG14-N3022 : Modern Bit Utilities". open-std.org. 2022-07-06. Archived from the original on December 24, 2022.
- "WG14-N2833 : Add timegm() as non-optional part of time.h". open-std.org. 2021-10-07. Archived from the original on December 1, 2021.
- "WG14-N2630 : formatted input/output of binary integer numbers" (PDF). open-std.org. 2021-01-01. Archived (PDF) from the original on December 14, 2022.
- "WG14-N3020 : Qualifier-preserving standard library functions" (PDF). open-std.org. 2022-06-13. Archived (PDF) from the original on October 13, 2022.
- "WG14-N2645 : Add support for preprocessing directives #elifdef and #elifndef" (PDF). open-std.org. 2020-01-25. Archived (PDF) from the original on November 28, 2022.
- "GCC 12 Adds Support For New #elifdef #elifndef Directives". phoronix. May 12, 2021. Archived from the original on December 27, 2022.
- "WG14-N3017 : #embed - a scannable, tooling-friendly binary resource inclusion mechanism". open-std.org. 2022-06-27. Archived from the original on December 24, 2022.
- "WG14-N2686 : #warning" (PDF). open-std.org. 2022-07-22. Archived (PDF) from the original on November 28, 2022.
- "WG14-N2799 : __has_include for C" (PDF). open-std.org. 2021-08-30. Archived (PDF) from the original on December 24, 2022.
- "WG14-N2553 : Querying attribute support" (PDF). open-std.org. 2020-08-04. Archived (PDF) from the original on October 14, 2022.
- "WG14-N3033 : Comma omission and comma deletion". open-std.org. 2022-07-20. Archived from the original on December 27, 2022.
- "WR14-N3042 : Introduce the nullptr constant". open-std.org. 2022-07-22. Archived from the original on December 24, 2022.
- "WG14-N2763 : Adding a Fundamental Type for N-bit integers" (PDF). open-std.org. 2021-06-21. Archived (PDF) from the original on December 27, 2022.
- "WG14-N3035 : _BitInt Fixes" (PDF). open-std.org. 2022-07-21. Archived (PDF) from the original on October 13, 2022.
- "WG14-N2867 : Checked N-Bit Integers" (PDF). open-std.org. 2021-11-28. Archived (PDF) from the original on December 14, 2022.
- "WG14-N2778 : Variably-Modified Types" (PDF). open-std.org. 2021-07-11. Archived (PDF) from the original on December 22, 2022.
- "WG14-N2607 : Compatibility of Pointers to Arrays with Qualifiers" (PDF). open-std.org. 2020-10-31. Archived (PDF) from the original on October 13, 2022.
- "WG14-N2899 : Not-so-magic - typeof for C". open-std.org. 2022-01-21. Archived from the original on December 24, 2022.
- "WG14-N3007 : Type inference for object definitions". open-std.org. 2022-06-10. Archived from the original on December 24, 2022.
- "WG14-N3037 : Improved Rules for Tag Compatibility (updates N3032)" (PDF).
- "WG14-N2775 : Literal suffixes for bit-precise integers" (PDF). open-std.org. 2021-07-13. Archived (PDF) from the original on December 27, 2022.
- "WG14-N2549 : Allow for binary integer constants" (PDF). open-std.org. 2020-07-30. Archived (PDF) from the original on December 22, 2022.
- "WG14-N2626 : Digit separators" (PDF). open-std.org. 2020-12-15. Archived (PDF) from the original on December 19, 2022.
- "WG14-N3030 : Enhancements to Enumerations". open-std.org. 2022-07-19. Archived from the original on November 26, 2022.
- "WG14-N3029 : Improved Normal Enumerations". open-std.org. 2022-07-19. Archived from the original on January 29, 2023.
- "WG14-N2935 : Make false and true first-class language features" (PDF). open-std.org. 2022-02-15. Archived (PDF) from the original on November 21, 2022.
- "WG14-N2934 : Revise spelling of keywords" (PDF). open-std.org. 2022-02-15. Archived (PDF) from the original on December 24, 2022.
- "WG14-N2508 : Free Positioning of Labels Inside Compound Statements" (PDF). open-std.org. 2020-03-28. Archived (PDF) from the original on December 27, 2022.
- "WG14-N2510 : Allowing unnamed parameters in a function definition" (PDF). open-std.org. 2020-04-09. Archived (PDF) from the original on December 24, 2022.
- "WG14-N2900 : Consistent, Warningless, and Intuitive Initialization with {}". open-std.org. 2022-01-01. Archived from the original on December 27, 2022.
- "WG14-N2975 : Relax requirements for variadic parameter lists" (PDF). open-std.org. 2022-04-15. Archived (PDF) from the original on November 28, 2022.
- "WG14-N2335 : Attributes in C" (PDF). open-std.org. 2019-03-09. Archived (PDF) from the original on October 26, 2022.
- "WG14-N2265 : Harmonizing static_assert with C++" (PDF). open-std.org. 2018-07-06. Archived (PDF) from the original on March 28, 2023.
- "Labels at the end of compound statements (C compatibility)" (PDF). 2022-01-13.
- "WG14-N2554 : Minor attribute wording cleanups" (PDF). open-std.org. 2020-08-04. Archived (PDF) from the original on November 28, 2022.
- "WG14-N2334 : The deprecated attribute" (PDF). open-std.org. 2019-01-22. Archived (PDF) from the original on October 19, 2022.
- "WG14-N2408 : The fallthrough attribute" (PDF). open-std.org. 2019-08-11. Archived (PDF) from the original on December 25, 2022.
- "WG14-N2270 : The maybe_unused attribute" (PDF). open-std.org. 2018-07-06. Archived (PDF) from the original on December 25, 2022.
- "WG14-N2267 : The nodiscard attribute" (PDF). open-std.org. 2018-07-06. Archived (PDF) from the original on October 19, 2022.
- "WG14-N2764 : The noreturn attribute" (PDF). open-std.org. 2021-06-21. Archived (PDF) from the original on December 25, 2022.
- "WG14-N2557 : Allow Duplicate Attributes" (PDF). open-std.org. 2020-09-01. Archived (PDF) from the original on November 28, 2022.
- "WG14-N2418 : Adding the u8 character prefix" (PDF). open-std.org. 2019-09-02. Archived (PDF) from the original on January 13, 2023.
- What is the point of the UTF-8 character literals proposed for C++17?; Stack Overflow.
- "WG14-N2341 : ISO/IEC TS 18661-2 - Floating-point extensions for C - Part 2: Decimal floating-point arithmetic" (PDF). open-std.org. February 26, 2019. Archived (PDF) from the original on November 21, 2022.
- "WG14-N2601 : Annex X - IEC 60559 interchange and extended types" (PDF). open-std.org. October 15, 2020. Archived (PDF) from the original on October 14, 2022.
- "WG14-N3018 : The constexpr specifier for object definitions". open-std.org. 2022-07-06. Archived from the original on December 24, 2022.
- "WG14-N2653 : char8_t: A type for UTF-8 characters and strings (Revision 1)". open-std.org. 2021-06-04. Archived from the original on May 27, 2023.
- "WG14-N2728 : char16_t & char32_t string literals shall be UTF-16 & UTF-32". open-std.org. 2021-05-15. Archived from the original on May 27, 2023.
- "WG14-N3038 : Introduce storage-class specifiers for compound literals". open-std.org. 2022-07-21. Archived from the original on November 26, 2022.
- "WG14-N2940 : Removing trigraphs??!" (PDF). open-std.org. 2022-03-02. Archived (PDF) from the original on October 26, 2022.
- "WG14-N2432 : Remove support for function definitions with identifier lists proposal" (PDF). open-std.org. September 25, 2019. Archived (PDF) from the original on December 27, 2022.
- "WG14-N2841 : No function declarators without prototypes". open-std.org. 2021-10-10. Archived from the original on November 12, 2022.
- "WG14-N2412 : Two's complement sign representation" (PDF). open-std.org. August 11, 2019. Archived (PDF) from the original on December 27, 2022.
- "WG14-N2993 : Make *_HAS_SUBNORM be obsolescent". open-std.org. 2022-06-06. Archived from the original on December 5, 2022.
- "GCC 9 Release Notes". GNU Project. Archived from the original on December 27, 2022.
- "Clang 9.0 - add new language mode for C2x". LLVM Project Repository. May 14, 2019. Archived from the original on December 27, 2022.
- "Pelles C - major changes between 10.00 and 11.00". smorgasbordet.com. Archived from the original on December 27, 2022.
External links
- C Language Working Group WG14 Documents
- N3096 - working draft of C23 standard - dated April 1, 2023