C2x
C2x is an informal name for the next (after C17) major C language standard revision.[1][2] It is expected to be voted on in 2023 and would therefore become C23.[3] The most recent publicly available draft of C23 was released on January 24, 2023.[4]
The first WG14 meeting for the C2x draft was held in October 2019, then virtual remote meetings were held due to COVID-19 pandemic in March/April 2020, October/November 2020, March/April 2021, August/September 2021, November/December 2021, January/February 2022, May 2022, July 2022, January 2023.[3][4]
Features
Changes integrated into the latest C23 draft are:[4]
- 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.[5] - add
memccpy()
function in<string.h>
to efficiently concatenate strings - similar to POSIX and SVID C extensions.[6] - add
strdup()
andstrndup()
functions in<string.h>
to allocate a copy of a string – similar to POSIX and SVID C extensions.[7] - add
memalignment()
function in<stdlib.h>
to determine the byte alignment of a pointer.[8] - 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.[9]- In the following, replace
*
withuc
,us
,ui
,ul
,ull
for five function names, or blank for a type-generic macro.[9] - add
stdc_count_ones*()
andstdc_count_zeros*()
to count number of 1 or 0 bits in value.[9] - add
stdc_leading_ones*()
andstdc_leading_zeros*()
to count leading 1 or 0 bits in value.[9] - add
stdc_trailing_ones*()
andstdc_trailing_zeros*()
to count trailing 1 or 0 bits in value.[9] - add
stdc_first_leading_one*()
andstdc_first_leading_zero*()
to find first leading bit with 1 or 0 in value.[9] - add
stdc_first_trailing_one*()
andstdc_first_trailing_zero*()
to find first trailing bit with 1 or 0 in value.[9] - 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).[9] - add
stdc_bit_floor*()
to determine the largest integral power of 2 that is not greater than value.[9] - add
stdc_bit_ceil*()
to determine the smallest integral power of 2 that is not less than value.[9] - add
stdc_bit_width*()
to determine number of bits to represent a value.[9]
- In the following, replace
- add
- Standard Library (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.[10] - add
%b
binary conversion specifier toscanf()
function family.[10] - add
0b
and0B
binary conversion support tostrtol()
andwcstol()
function families.[10] - 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.[11]
- add
- Preprocessor
-
- add
#elifdef
and#elifndef
directives[12] are essentially equivalent to#elif defined
and#elif !defined
. Both directives were added to C++23 and GCC 12 too.[13] - add
#embed
directive for binary resource inclusion.[14] - add
#warning
directive for diagnostics.[15] - add
__has_include
allowing the availability of a header to be checked by preprocessor directives.[16] - add
__has_c_attribute
allowing the availability of an attribute to be checked by preprocessor directives.[17] (see C++ compatibility group below 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.[18]
- add
- Types
-
- add
nullptr_t
type.[19] - add
_BitInt(N)
andunsigned _BitInt(N)
types for bit-precise integers. AddBITINT_MAXWIDTH
macro for maximum bit width.[20][21] Addckd_add()
,ckd_sub()
,ckd_mul()
macros for checked integer operations.[22] - Variably-modified types (but not VLAs which are automatic variables allocated on the stack) become a mandatory feature.[23]
- Standardization of the
typeof(...)
operator.[24] - 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.[25]
- add
- Constants
-
- add
nullptr
constant fornullptr_t
type.[19] - add
wb
anduwb
integer literal suffixes for_BitInt(N)
andunsigned _BitInt(N)
types,[26] 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,[27] such as0b10101010
(equating to 0xAA). - add
'
digit separator to literal constants,[28] 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
.[29] - allow
enum
s with no fixed underlying type to store values that aren't representable byint
.[30]
- add
- C++ compatibility
-
- add C++11 style attribute syntax[31] using double square brackets
'"`UNIQ--nowiki-00000048-QINU`"'
. Add attributes [32]'"`UNIQ--nowiki-0000004B-QINU`"'
,[33]'"`UNIQ--nowiki-0000004E-QINU`"'
,[34]'"`UNIQ--nowiki-00000051-QINU`"'
,[35]'"`UNIQ--nowiki-00000054-QINU`"',
[36] and'"`UNIQ--nowiki-00000057-QINU`"'
attribute for compatibility with C++11, then deprecate_Noreturn
,noreturn
, header<stdnoreturn.h>
features introduced in C11.[37] Duplicate attributes are allowed for compatibility with C++23.[38] - add
u8
prefix for character literals to represent UTF-8 encoding for compatibility with C++17.[39][40] - add
#elifdef
and#elifndef
preprocessing directives for compatibility with C++23.[12] (see preprocessor group above)
- add C++11 style attribute syntax[31] using double square brackets
- 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.[41][42]
- Single-argument
Static assert
.[43] - Labels can appear before declarations and at the end of compound statements.[44]
- Unnamed parameters in function definitions.[45]
- Better support for using
const
with arrays.[46] - Zero initialization with
{}
(including initialization of VLAs).[47] alignas
,alignof
,bool
,true
,false
,static_assert
,thread local
become keywords.[48][49]- The
constexpr
specifier for objects but not functions, unlike C++'s equivalent.[50] - 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.[51] - add the
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.[52] - allow storage class specifiers to appear in compound literal definition.[53]
Obsolete features
Some old obsolete features are either removed or deprecated:
Compiler support
The GCC 9,[59] Clang 9.0,[60] and Pelles C 11.00[61] compilers implement an experimental compiler flag to support this standard.
See also
- C++23, C++20, C++17, C++14, C++11, C++03, C++98, versions of the C++ programming language standard
- Compatibility of C and C++
References
- ↑ "History of C". 2022-06-27. https://en.cppreference.com/w/c/language/history.
- ↑ "WG14-N2086 : C2x Charter". 2016-09-20. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2086.htm.
- ↑ 3.0 3.1 "WG14-N2984 : Revised C23 Schedule". 2022-05-05. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2984.pdf.
- ↑ 4.0 4.1 4.2 "WG14-N3088 : Draft for ISO/IEC 9899:2023". January 24, 2023. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3088.pdf.
- ↑ "WG14-N2897 : memset_explicit()". 2021-12-27. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2897.htm.
- ↑ "WG14-N2349 : Toward more efficient string copying and concatenation". 2019-03-18. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2349.htm.
- ↑ "WG14-N2353 : strdup() and strndup()". 2019-03-18. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2353.htm.
- ↑ "WG14-N2974 : Queryable pointer alignment". 2022-04-15. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2974.pdf.
- ↑ 9.00 9.01 9.02 9.03 9.04 9.05 9.06 9.07 9.08 9.09 9.10 "WG14-N3022 : Modern Bit Utilities". 2022-07-06. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3022.htm.
- ↑ 10.0 10.1 10.2 "WG14-N2630 : formatted input/output of binary integer numbers". 2021-01-01. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2630.pdf.
- ↑ "WG14-N3020 : Qualifier-preserving standard library functions". 2022-06-13. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3020.pdf.
- ↑ 12.0 12.1 "WG14-N2645 : Add support for preprocessing directives #elifdef and #elifndef". 2020-01-25. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2645.pdf.
- ↑ "GCC 12 Adds Support For New #elifdef #elifndef Directives". May 12, 2021. https://www.phoronix.com/news/GCC-12-elifdef-elifndef.
- ↑ "WG14-N3017 : #embed - a scannable, tooling-friendly binary resource inclusion mechanism". 2022-06-27. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm.
- ↑ "WG14-N2686 : #warning". 2022-07-22. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2686.pdf.
- ↑ "WG14-N2799 : __has_include for C". 2021-08-30. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2799.pdf.
- ↑ "WG14-N2553 : Querying attribute support". 2020-08-04. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2553.pdf.
- ↑ "WG14-N3033 : Comma omission and comma deletion". 2022-07-20. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3033.htm.
- ↑ 19.0 19.1 "WR14-N3042 : Introduce the nullptr constant". 2022-07-22. https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm.
- ↑ "WG14-N2763 : Adding a Fundamental Type for N-bit integers". 2021-06-21. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2763.pdf.
- ↑ "WG14-N3035 : _BitInt Fixes". 2022-07-21. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3035.pdf.
- ↑ "WG14-N2867 : Checked N-Bit Integers". 2021-11-28. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2867.pdf.
- ↑ "WG14-N2778 : Variably-Modified Types". 2021-07-11. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2778.pdf.
- ↑ "WG14-N2899 : Not-so-magic - typeof for C". 2022-01-21. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2899.htm.
- ↑ "WG14-N3007 : Type inference for object definitions". 2022-06-10. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm.
- ↑ "WG14-N2775 : Literal suffixes for bit-precise integers". 2021-07-13. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2775.pdf.
- ↑ "WG14-N2549 : Allow for binary integer constants". 2020-07-30. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2549.pdf.
- ↑ "WG14-N2626 : Digit separators". 2020-12-15. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2626.pdf.
- ↑ "WG14-N3030 : Enhancements to Enumerations". 2022-07-19. https://open-std.org/JTC1/SC22/WG14/www/docs/n3030.htm.
- ↑ "WG14-N3029 : Improved Normal Enumerations". 2022-07-19. https://open-std.org/JTC1/SC22/WG14/www/docs/n3029.htm.
- ↑ "WG14-N2335 : Attributes in C". 2019-03-09. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2335.pdf.
- ↑ "WG14-N2554 : Minor attribute wording cleanups". 2020-08-04. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2554.pdf.
- ↑ "WG14-N2334 : The deprecated attribute". 2019-01-22. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2334.pdf.
- ↑ "WG14-N2408 : The fallthrough attribute". 2019-08-11. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2408.pdf.
- ↑ "WG14-N2270 : The maybe_unused attribute". 2018-07-06. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2270.pdf.
- ↑ "WG14-N2267 : The nodiscard attribute". 2018-07-06. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2267.pdf.
- ↑ "WG14-N2764 : The noreturn attribute". 2021-06-21. https://open-std.org/JTC1/SC22/WG14/www/docs/n2764.pdf.
- ↑ "WG14-N2557 : Allow Duplicate Attributes". 2020-09-01. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2557.pdf.
- ↑ "WG14-N2418 : Adding the u8 character prefix". 2019-09-02. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2418.pdf.
- ↑ 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". February 26, 2019. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2341.pdf.
- ↑ "WG14-N2601 : Annex X - IEC 60559 interchange and extended types". October 15, 2020. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2601.pdf.
- ↑ "Harmonizing static_assert with C++". https://open-std.org/JTC1/SC22/WG14/www/docs/n2265.pdf.
- ↑ "WG14-N2508 : Free Positioning of Labels Inside Compound Statements". 2020-03-28. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf.
- ↑ "WG14-N2510 : Allowing unnamed parameters in a function definition". 2020-04-09. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2510.pdf.
- ↑ "WG14-N2607 : Compatibility of Pointers to Arrays with Qualifiers". 2020-10-31. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2607.pdf.
- ↑ "WG14-N2900 : Consistent, Warningless, and Intuitive Initialization with {}". 2022-01-01. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm.
- ↑ "WG14-N2935 : Make false and true first-class language features". 2022-02-15. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2935.pdf.
- ↑ "WG14-N2934 : Revise spelling of keywords". 2022-02-15. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2934.pdf.
- ↑ "WG14-N3018 : The constexpr specifier for object definitions". 2022-07-06. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3018.htm.
- ↑ "WG14-N2975 : Relax requirements for variadic parameter lists". 2022-04-15. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf.
- ↑ "char8_t: A type for UTF-8 characters and strings (Revision 1)". https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm.
- ↑ "WG14-N3038 : Introduce storage-class specifiers for compound literals". 2022-07-21. https://open-std.org/JTC1/SC22/WG14/www/docs/n3038.htm.
- ↑ "WG14-N2940 : Removing trigraphs??!". 2022-03-02. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2940.pdf.
- ↑ "WG14-N2432 : Remove support for function definitions with identifier lists proposal". September 25, 2019. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2432.pdf.
- ↑ "WG14-N2841 : No function declarators without prototypes". 2021-10-10. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm.
- ↑ "WG14-N2412 : Two’s complement sign representation". August 11, 2019. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf.
- ↑ "WG14-N2993 : Make *_HAS_SUBNORM be obsolescent". 2022-06-06. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2993.htm.
- ↑ "GCC 9 Release Notes". https://gcc.gnu.org/gcc-9/changes.html#c.
- ↑ "Clang 9.0 - add new language mode for C2x". May 14, 2019. https://github.com/llvm/llvm-project/commit/d06f3917913d2558b771ccc48d838f8cd8993c01.
- ↑ "Pelles C - major changes between 10.00 and 11.00". http://www.smorgasbordet.com/pellesc/changes_1000_1100.htm.
External links
Preceded by C17 |
C language standards | Latest |