Can’t wait for C23? Project editor shares details and lets devs know where they can still help

C23

As promised earlier this year, C project editor JeanHeyd Meneide used a gap in their schedule to inform developers about the “big ticket items” that got accepted into the next version of the C standard, which is supposed to be voted on in 2023.

Integer handling seems to have been one of the major themes for C23, as highlights of the language update will include a fundamental type for N-bit integers and the implementation of a proposal called “towards integer safety”. The latter comes in the form of a new header called stdckdint.h which is hoped to reduce the amount of undefined behaviour leading to overflows and other potentially exploitable events when performing integer operations. It contains macros for addition, subtraction, and multiplication that will detect overflow and let users know if the result of the operation is safe to use or not.

The new fundamental type _BitInt(N), with N being the number of bits the integer should contain, is meanwhile meant to turn C into more of a contender for embedded programming, since it provides an explicit bit-width across systems. Like that, developers don’t have to use the next largest data type (potentially wasteful) and do manual masking or shifting (error-prone) anymore if they want to make sure signage changes etc won’t lead to unexpected outcomes. 

To make code containing large numeric constants easier to read, the new C version will allow the use of apostrophes as digit separators, so that developers can write 3’237’635’918 instead of just stringing everything together. Speaking of constants, C23 is also planned to introduce binary integer constants, which on top of that will be printable (or used with scanf and strto* functions) via a newly added “%b” specifier.

The printing process itself will hopefully become a bit more secure through the addition of specific width length modifiers to formatted IO functions. Currently, there isn’t a cross-platform mechanism to allow users to define the width of an extended integer type when passing it on as an argument. The modifiers meant to rectify this will adhere to the pattern %w128d where w stands for width, followed by the length of the value, and a type identifier which can be used like printf("%w128d", my_128bit_integer);.

Other than that C23 will finally get shorthand preprocessing directives for #elif defined(identifier) and #elif !defined(identifier). #elifdef and #elifndef work in the same way as #ifdef and #ifndef and are meant to make the language both more expressive and predictable, especially for those new to C.

Tool developers might be interested in the #warning directive which will be part of C23. This can be used to notify users of potential problems and deprecations without stopping their compilation process — something using #error would. The update is also meant to contain the __has_include feature which allows programmers to test if a specific header file exists at preprocessing time and has been present in C++ since its 2017 edition.

While the changes mentioned might not be as impressive as those that made their way into the latest version of the C++ standard, the planned enhancements for C23 will surely help to move the language into a safer direction. If all goes according to plan, the release will also see a closer alignment of C and C++, as the language developers have introduced proposals to clarify atomics compatibility between both languages and additional delimited escape sequences (PDF) amongst other things. 

Developers who’d still like to see the lambdas proposal making its way into the next release could always help by coming up with an implementation for a compiler before mid-2022, Meineide wrote on Twitter. First reactions to the comment give reason for cautious optimism given the timeline, but we’ll have to wait and see if someone follows through and will indeed produce a result good enough to help the feature along.