A change has been made to the codebase forming the basis of the scheduled release of the GCC 15 compiler set for spring next year, which includes using the C23 standard with GNU extensions ("-std=gnu23") by default when compiling C programs. Previously, the default was the C17 standard ("-std=gnu17"). This change may potentially lead to issues when building existing projects, as the new standard includes differences, such as the addition of the nullptr constant, the _BitInt(n) type, and the keywords bool, true, and false, which may conflict with identifiers of the same name specified in applications.
The C23 standard (ISO/IEC 9899:2024) was officially published by the International Organization for Standardization (ISO) on October 31, 2024. Among the changes in the new standard are:
- The ability to define functions in K&R C style, used prior to the adoption of the ANSI C specification and described in the book 'The C Programming Language' by Kernighan and Ritchie, has been removed. The K&R style involves describing argument types after the function definition, for example, 'int add(a, b) int a, b; {}'
- Unnamed function parameters — the option to omit names for unused parameters when defining functions (as in C++). For example, one can now write 'int f(int, int) { return 7; }'.
- Support for the '[[name]]' syntax for defining attributes as in C++ ('[[gnu::const]]', '[[deprecated]]', '[[fallthrough]]', '[[maybe_unused]]', '[[nodiscard]]', '[[noreturn]]', '[[reproducible]]', '[[unsequenced]]'). For example, the [[noreturn]] attribute allows you to specify that a function does not return values (the stdnoreturn.h header file and the '_Noreturn' specifier have been deprecated).
- Support for the u8" syntax for defining constants with characters in UTF-8.
- The char8_t type has been added for strings and characters in UTF-8 encoding, as well as functions for converting strings with multibyte characters mbrtoc8() and c8rtomb().
- The behavior of the 'auto' keyword has been changed to infer the type when defining objects, allowing the use of the 'auto' specifier instead of a type to define the type of variables based on the type of expression for their initialization. For example: 'auto y = cos(x);'.
- Functions with an empty argument list are now treated as functions that do not take arguments.
- Support for header files and has been added, including macros, functions, and types for checking integer calculations.
- The placement of labels is now allowed anywhere within compound expressions.
- Support for trigraphs in the code has been discontinued; sequences of three ASCII characters processed as one character, such as the sequence "??=", could replace "#". After the advent of Unicode, the support for trigraphs became unnecessary.
- Support for the prefixes "0b" and "0B" for specifying integer values in binary form has been added, e.g., "int b = 0b101010".
- The keywords bool, static_assert, alignas, alignof, and thread_local have been added.
- Empty braces "{}" are now allowed for initializing to zero values, i.e., it is now possible to write "struct S { int x, y } s = {};".
- The ability to specify any universal character names in character and string literals has been provided. For example, "int \u0024 = 0;".
- The macro "unreachable" has been added to "stddef.h".
- A new type nullptr_t and the constant nullptr for defining null pointers have been introduced, which can convert to any pointer type and represent the NULL variant that is not tied to integer types or type void*. For instance, one can specify "void func(nullptr_t); func(0); func((void *)0);".
- The types "_BitInt (N)" and "unsigned _BitInt (N)" have been added to define integers with a specified number of bits, along with decimal types with floating point, namely "_Decimal32", "_Decimal64", and "_Decimal128", and functions to work with such types.
- The ability to use the character "‘" for visually separating digits in numbers (for example, "1’000’000") has been added.
- Structures, unions, and enumerations are now allowed to be defined more than once in the same scope with the same content and repeating tag.
- The operators typeof and typeof_unqual have been included in the standard.
- Support for using the constexpr specifier for defining objects has been introduced.
- The macros INFINITY, NAN, FLT_NORM_MAX, DBL_NORM_MAX, and LDBL_NORM_MAX have been added to the header files float.h and math.h.
- The preprocessor directives #elifdef, #elifndef, #warning, and #embed have been added. The "#embed" directive is intended for integrating binary resources.
- The use of variadic lists (variable number of arguments) has been simplified.
- The capabilities of enumerations (enum) have been expanded.
- Support for the substitution "%b" for handling binary values in printf() and scanf() function families has been added.
- Calling the realloc() function with a zero size has been classified as undefined behavior.
- The functions memccpy(), strdup(), strndup(), gmtime_r(), and localtime_r() have been standardized.
- The functions asctime() and ctime() have been deprecated.
- The macros static_assert and thread_local have been moved to the keywords category.
Source: opennet.ru
