Английская Википедия:C23 (C standard revision)
Шаблон:Short description Шаблон:C language revisions
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 2024.
Features
Changes integrated into the latest working draft of C23 are listed below.[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.[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 is 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 did not 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 Шаблон:C-lang and Шаблон:C-lang directives,[14] which are essentially equivalent to Шаблон:C-lang and Шаблон:C-lang. Both directives were added to C++23 standard and GCC 12.[15]
- Add Шаблон:C-lang directive for binary resource inclusion and Шаблон:C-lang allowing the availability of a resource to be checked by preprocessor directives.[16]
- Add Шаблон:C-lang directive for diagnostics.[17]
- Add Шаблон:C-lang allowing the availability of a header to be checked by preprocessor directives.[18]
- Add Шаблон:C-lang allowing the availability of an attribute to be checked by preprocessor directives.[19] (see "C++ compatibility" group for new attribute feature)
- Add Шаблон:C-lang 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|Шаблон:Code]], a null pointer type.[21]
- Add Шаблон:C-lang and Шаблон:C-lang types for bit-precise integers. Add Шаблон:C-lang macro for maximum bit width.[22][23]
- Add
ckd_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 Шаблон:C-lang 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|Шаблон:Code]] constant for
nullptr_t
type.[21] - Add
wb
anduwb
integer literal suffixes for Шаблон:C-lang and Шаблон:C-lang types,[30] such as Шаблон:C-lang yields anunsigned _BitInt(3)
, and Шаблон:C-lang yields asigned _BitInt(4)
which has three value bits and one sign bit. - Add
0b
and0B
binary literal constant prefixes,[31] such as Шаблон:C-lang (equating to 0xAA). - Add
'
digit separator to literal constants,[32] such as Шаблон:C-lang (equating to 0xFEDCBA98), Шаблон:C-lang (equating to 299792458), Шаблон:C-lang (equating to 1.414213562). - Add the ability to specify the underlying type of an
enum
.[33] - Allow Шаблон:C-langs with no fixed underlying type to store values that are not representable by Шаблон:C-lang.[34]
Keywords
- Add Шаблон:C-lang and Шаблон:C-lang keywords.[35]
- Add Шаблон:C-lang, Шаблон:C-lang, Шаблон:C-lang, Шаблон:C-lang, [[thread-local storage|Шаблон:Code]] keywords. Previously defined keywords become alternative spellings: Шаблон:C-lang, Шаблон:C-lang, Шаблон:C-lang, Шаблон:C-lang, Шаблон:C-lang.[36]
- Add Шаблон:C-lang keyword (see "types" group)
- Add Шаблон:C-lang and Шаблон:C-lang keywords (see "types" group)
- Add Шаблон:C-lang keyword (see "constants" group)
- Add Шаблон:C-lang keyword (see "other" group)
- Add Шаблон:C-lang, Шаблон:C-lang, Шаблон:C-lang 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 Шаблон:C-lang 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 Шаблон:C-lang.
- 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] Шаблон:C-lang,[45] Шаблон:C-lang,[46] Шаблон:C-lang,[47] Шаблон:C-lang,[48] and Шаблон:C-lang attribute for compatibility with C++11, then deprecate Шаблон:C-lang, Шаблон:C-lang, 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 Шаблон:C-lang is equivalent to Шаблон:C-lang). - Add
u8
prefix for character literals to represent UTF-8 encoding for compatibility with C++17.[51][52] - Add Шаблон:C-lang and Шаблон:C-lang 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 Шаблон:C-lang type for storing UTF-8 encoded data and change the type of u8 character constants and string literals to Шаблон:C-lang. Also, the functions
mbrtoc8()
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 Шаблон:C-lang strings and literals shall be UTF-16 encoded, and all Шаблон:C-lang 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 Шаблон:C-lang 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
- 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
External links
- C Language Working Group WG14 Documents
- N3096 - working draft of C23 standard - dated April 1, 2023
Шаблон:S-start Шаблон:S-bef Шаблон:S-ttl Шаблон:S-non Шаблон:End
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 4,0 4,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 10,00 10,01 10,02 10,03 10,04 10,05 10,06 10,07 10,08 10,09 10,10 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 12,0 12,1 12,2 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 14,0 14,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 21,0 21,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ What is the point of the UTF-8 character literals proposed for C++17?; Stack Overflow.
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web