1# C23 language changes 2 3## Breaking changes 4 5### `void foo()` now means `void foo(void)` 6In C17 and earlier, `void foo()` means "I haven't yet told you how many 7arguments this function has". In C23, it's equivalent to C++ and means "this 8function has no arguments". This may surface as a function pointer type 9mismatch, because previously `()` matched functions taking any arguments, 10whereas in C23 it only matches functions taking no arguments. 11 12Fix: in cases where your function does have arguments, declare them. 13 14### Undeclared identifiers are now errors 15In C17 and earlier, calling `foo(123)` without a declaration for `foo()` 16produced a warning. In C23 this is an error instead. One common special case of 17this is code that's explicitly ignoring such warnings to call functions that are 18GNU extensions; such code should be fixed to ensure that `_GNU_SOURCE` is 19defined before any header is included instead (often by adding `-D_GNU_SOURCE` 20to the cflags in the build file). 21 22Fix: add the missing forward declaration or `#include` (or `-D_GNU_SOURCE`). 23 24### `bool`/`true`/`false` are now keywords 25In C17 and earlier, only code that included `<stdbool.h>` would have standard 26definitions for these (typically macros for `_Bool`/`1`/`0`). In C23 these are 27keywords and should no longer be defined in your code. 28 29Fix: delete any definitions of `bool`/`true`/`false` if you only need to build 30as C23, or switch to `#include <stdbool.h>` for compatibility back to C99. 31 32### `false` is no longer `0` 33In C17 and earlier, it was common for true and false to be defined as 1 and 0 34(either by `<stdbool.h>` or by user-provided `#define`/`enum`). This meant that 35`false` (as 0) could be implicitly converted to `NULL`. In C23, a function that 36returns (or takes) a pointer can no longer return `false` (or be passed 37`false`). 38 39Fix: return/pass `NULL` (or `nullptr` for C23-only code) instead of `false` 40in pointer contexts. 41 42### `unreachable()` is now a predefined function-like macro in `<stddef.h>` 43In C17 and earlier, `unreachable()` was available for your own macros/functions. 44In C23 there's a standard definition. 45 46Fix: delete your `unreachable()` if it was just equivalent to 47`__builtin_unreachable()` or rename it if it had different behavior. 48 49### K&R prototypes are no longer valid 50In C17 and earlier, K&R function prototypes were deprecated but still allowed. 51In C23 K&R prototypes are no longer allowed. 52 53Fix: rewrite any K&R prototypes as ANSI/ISO prototypes. 54 55 56## Non-breaking changes 57 58### Unused function parameters can now be anonymous 59In C17 and earlier you'd have to use `__attribute__((unused))` on an unused 60function parameter. In C23 you can just omit the parameter name instead, 61like `void* pthread_callback_fn(void*) {` (as in C++). 62 63### New standard attributes 64C23 adds `[[deprecated("reason")]]`, `[[fallthrough]]`, `[[nodiscard]]` (the 65equivalent of the clang attribute `warn_unused_result`), 66`[[maybe_unused]]` (the equivalent of the clang attribute `unused`), 67and `[[noreturn]]` (equivalent to C11 `_Noreturn`). 68Most of these have been available before via `__attribute__` or other syntax, 69but are now standard. 70 71### `#embed` 72You can now include binary data directly into an array or string: https://en.cppreference.com/w/c/preprocessor/embed 73 74### `void foo(...)` is now allowed 75In C17 and earlier, a varargs function needed a non-varargs argument. 76In C23 this is allowed (as in C++). 77 78### `enum` base types 79You can now say `enum E : long { ... }` to explicitly choose the base type of 80your enum (as in C++, and already supported by clang as an extension). 81 82### `nullptr` constant 83There is now a `nullptr` constant (as in C++), 84and a corresponding `nullptr_t` type for that constant. 85 86### `constexpr` 87There is now a limited form of `constexpr` for defining `const` variables 88(similar to, but much more limited than C++ constexpr). 89 90 91## Library changes 92 93Library changes are not covered here because bionic does not make library 94functionality available based on target C version, since the target API level 95distinctions are confusing enough already. 96 97See [status.md](status.md) for what functionality went into which API level. 98