iTranslated by AI
The Next C Standard (C23) Has Apparently Been Finalized
I briefly introduced C23 in Modern C and the Next C Standard (C23) as well.
Now that the contents to be included in C23 have mostly been finalized, I would like to introduce them again.
The latest publicly available Working Draft at the time of writing is N2912 N3047 N3054 N3096. However, there is also the first draft for C2y, N3220, which might be closer to the actual content.
I am also referring to posts from meeting participants regarding the details:
So, here are the main features coming to C23:
Main features in C23
-
Incorporation of POSIX features:
strdup,strndup,memccpy,gmtime_r,localtime_r -
Incorporation of C++ features:
- Attributes with
[[]]: In the standard, there are 8 (effectively 7):[[nodiscard]],[[maybe_unused]],[[deprecated]],[[fallthrough]],[[noreturn]],[[_Noreturn]],[[reproducible]],[[unsequenced]]. Additionally, vendor-specific ones like[[vendor::attr]]can be used depending on the implementation. -
char8_t(unlike C++, this is a typedef ofunsigned char) -
u8character literals (Note:u8string literals were already introduced in C11) - Predefined
bool,true,false,static_assert,alignof,alignas,thread_local - Single-argument
static_assert -
auto(N3007)- In GCC and others, a C++-like
autowas already available via the__auto_typekeyword. This seems useful for macros, etc. Typeof (Using the GNU Compiler Collection (GCC))
- In GCC and others, a C++-like
- Constants via
constexpr. Not applicable to functions. (N3018) -
enumwith a specified underlying type (N3021) -
nullptr(N3019) - Digit separators
- Binary literals
- Initialization with
= {}(N2900)
- Attributes with
-
Floating-point numbers
- Support for IEEE 754-2019. Previously, it referenced IEEE 754-1985.
- Parts of TS 18661-1, TS 18661-2, and TS 18661-4 have been incorporated into the main text, and TS 18661-3 (such as the
_FloatNtypes) has been incorporated as Annex H (the previous Annex H was Language Independent Arithmetic). - New pragmas include
#pragma STDC FENV_ROUND,#pragma STDC FENV_DEC_ROUND, etc.
-
Removal of K&R style function definitions
- Also, if the parameter list of a function declaration without a definition is empty, it will now represent "the function takes no arguments" (N2841).
-
Ability to define variadic functions without mandatory arguments (N2975)
- The second argument of
va_startbecomes optional. - In C++, defining variadic functions without mandatory arguments has been possible and used in things like SFINAE, but since
va_startcould not be used, the arguments could not be accessed.
- The second argument of
-
Two's complement representation is now mandatory
-
#elifdef,#elifndef -
#embed(N3017)- Allows for embedding files.
-
#warning -
typeof(N2927)- C++'s
decltypedepends on reference types, so it couldn't be brought over to C. - The reason for not adding underscores to the keyword might be that various compilers already provide the
typeofkeyword and probably nobody is using it as a variable name (just a guess). -
In N2927,remove_qualswas introduced alongsidetypeof. On the other hand, there was a proposal (N2930) to use a name likeunqual_typeofinstead ofremove_quals—so which one did it end up being?typeof_unqualis included in addition totypeof.
- C++'s
-
unreachable()(N2826)- Similar to GCC/Clang's
__builtin_unreachable(), MSVC's__assume(false), or C++23'sstd::unreachable(). Useful for certain optimizations.
- Similar to GCC/Clang's
-
_BitInt -
memset_explicit- Previously,
memset_sin Annex K was similar, but the arguments are slightly different.
- Previously,
-
Variable-length arrays that are not allocated on the stack (like pointers or arguments) are promoted to mandatory features.
-
Integer operations with overflow checking:
ckd_add,ckd_sub,ckd_mulin<stdckdint.h>(N2683) -
__has_include -
Bitwise operations such as popcount, clz, and ctz in
<stdbit.h>:stdc_count_ones,stdc_leading_zeros,stdc_trailing_zeros, etc. (part of N3022)
There isn't enough time to explain each feature in detail here. I have written articles about some of them:
- C's bool type and its name — I'm tired of _Bool —
-
Overflow checking in C (
<stdckdint.h>) - New features in C23: Introduction to advanced bit manipulation <stdbit.h>
- Improvements in C23: Maintaining constness in string search functions
For some other features, here are some articles by yohhoy:
- C2x Standard Attributes (attribute) - yohhoy's diary
- #elifdef and #elifndef - yohhoy's diary
- Binary literals in standard C - yohhoy's diary
- realloc(ptr, 0) is scheduled to be deprecated - yohhoy's diary
- Binary format output in standard C - yohhoy's diary
- nullptr constant in standard C - yohhoy's diary
- reproducible/unsequenced attributes - yohhoy's diary
- typeof operator in standard C - yohhoy's diary
- #embed directive - yohhoy's diary
- R.I.P. "= {0}" - yohhoy's diary
Articles by members of the standardization committee are also informative:
It seems that a summary of the feature list is also available on cppreference.
GCC Support Status
In recent versions of GCC, some features can be used with -std=c2x (and also with -std=c23 starting from GCC 14).
- GCC 10 Release Series — Changes, New Features, and Fixes - GNU Project
- GCC 11 Release Series — Changes, New Features, and Fixes - GNU Project
- GCC 12 Release Series — Changes, New Features, and Fixes - GNU Project
- GCC 13 Release Series — Changes, New Features, and Fixes - GNU Project
- GCC 14 Release Series — Changes, New Features, and Fixes - GNU Project
In GCC 10:
- Attributes with
[[]]: Standard[[deprecated]],[[fallthrough]],[[maybe_unused]], and[[gnu::something]] - UTF-8 character literals:
u8''
and others were implemented. In GCC 11:
-
trueandfalsedefined in<stdbool.h>now have thebooltype -
[[nodiscard]]attribute __has_c_attribute
and others were added. In GCC 12:
- Digit separators
-
#elifdef,#elifndef
and others were added. In GCC 13:
nullptr- Extensions to
enum autoconstexpr-
typeof,typeof_unqual - Keywording of
alignas,alignof,bool,false,static_assert,thread_local,true -
[[noreturn]]attribute = {}unreachable()- Removal of functions without prototypes
and others were added. In GCC 14:
_BitInt- Multiple definitions of compatible structs, unions, and enums
<stdckdint.h>
among other features have been implemented.
Clang Support Status
Clang also seems to support some of the features of C23 starting from version 9 with -std=c2x.
This article is updated from time to time. Please see GitHub for the change history.
Discussion