C23 (C standard revision)

From testwiki
Jump to navigation Jump to search

Template:Short description Template:C language revisions C23, formally ISO/IEC 9899:2024, is the current open standard for the C programming language, which supersedes C17 (standard ISO/IEC 9899:2018).[1] It was started in 2016 informally as C2x,[2] and was published on October 31, 2024.[3] The freely available draft most similar to the one published is document N3220[4] (see Available texts, below). 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.

GCC has support for C23 (and incomplete for C2Y).[6] Clang has partial support for C23.

In C23, the value of __STDC_VERSION__ changes from 201710L to 202311L. The common names "C17" and "C23" reflect these values, which are frozen prior to final adoption, rather than the years in the ISO standards identifiers (9899:2018 and 9899:2024).

Features

Changes integrated into the latest working draft of C23 are listed below.[7]

Constants

Keywords

Types

  • Add [[nullptr_t|Template:Code]], a null pointer type.[8]
  • Add Template:C-lang and Template:C-lang types for bit-precise integers. Add Template:C-lang macro for maximum bit width.[16][17]
  • Add ckd_add(), ckd_sub(), ckd_mul() macros for checked integer operations.[18]
  • Variably-modified types (but not VLAs which are automatic variables allocated on the stack) become a mandatory feature.[19]
  • Better support for using const with arrays.[20]
  • Standardization of the typeof(...) operator.[21]
  • The meaning of the Template: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).[22]
  • Compatibility rules for structure, union, and enumerated types were changed to allow a redeclaration of a compatible type with the same tag.[23]
  • Exact-width integer may now exceed Template:Code (N2888).[24]
  • Specify that [u]intN_t when defined must designate the same type as [u]int_leastN_t[25]

Syntax

  • Labels can appear before declarations and at the end of compound statements.[26]
  • Unnamed parameters in function definitions.[27]
  • Zero initialization with {} (including initialization of VLAs).[28]
  • Variadic functions no longer need a named argument before the ellipsis and the Template:C-lang macro no longer needs a second argument nor does it evaluate any argument after the first one if present.[29]
  • Add C++11 style attribute syntax[30] using double square brackets Template:C-lang. In addition to C++11 attributes listed below, add new attributes:
    • [[unsequenced]][31] allows compiler optimizations for functions producing repeatable outputs only based on their parameters
    • [[reproducible]],[31] similar to [[unsequenced]], but for functions whose call order also matters
  • Add single-argument static_assert for compatibility with C++17.[32]
  • Functions with no arguments listed in the prototype (e.g. void foo()) are understood as taking no arguments (see removal of K&R function declarations)

Preprocessor

C++ compatibility

Other

  • 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.[50][51]

Standard Library

Existing functions

  • Add %b binary conversion specifier to printf() function family.[56]
  • Add %b binary conversion specifier to scanf() function family.[56]
  • Add 0b and 0B binary conversion support to functions strtol(), strtoll(), strtoul(), strtoull(), and their wide counterparts wcstol(), wcstoll(), wcstoul(), wcstoull(). If a sign is present, the 0b or 0B follows the sign.[56]
  • Add specific width modifiers %wN and %wfN to printf() function family.[25]
  • Add specific width modifiers %wN and %wfN to scanf() function family.[25]
  • Make the functions bsearch(), bsearch_s(), memchr(), strchr(), strpbrk(), strrchr(), strstr(), and their wide counterparts wmemchr(), wcschr(), wcspbrk(), wcsrchr(), wcsstr() return a const qualified object if one was passed to them.[57]

New functions

  • Add memset_explicit() function in <string.h> to erase sensitive data, where memory store must always be performed regardless of optimizations.[58]
  • Add memccpy() function in <string.h> to efficiently concatenate strings – similar to POSIX and SVID C extensions.[59]
  • Add strdup() and strndup() functions in <string.h> to allocate a copy of a string – similar to POSIX and SVID C extensions.[60]
  • Add memalignment() function in <stdlib.h> to determine the byte alignment of a pointer.[61]
  • Add free_sized() and free_aligned_sized() functions in <stdlib.h> to free memory more efficiently when the size is known.[62]
  • Add bit utility functions / macros / types in new header <stdbit.h> to examine many integer types. All start with stdc_ to minimize conflict with legacy code and 3rd party libraries.[63]
    • In the following, replace * with uc, us, ui, ul, ull for five function names, or blank for a type-generic macro.[63]
    • Add stdc_count_ones_*() and stdc_count_zeros_*() to count number of 1 or 0 bits in value.[63]
    • Add stdc_leading_ones_*() and stdc_leading_zeros_*() to count leading 1 or 0 bits in value.[63]
    • Add stdc_trailing_ones_*() and stdc_trailing_zeros_*() to count trailing 1 or 0 bits in value.[63]
    • Add stdc_first_leading_one_*() and stdc_first_leading_zero_*() to find first leading bit with 1 or 0 in value.[63]
    • Add stdc_first_trailing_one_*() and stdc_first_trailing_zero_*() to find first trailing bit with 1 or 0 in value.[63]
    • 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).[63]
    • Add stdc_bit_floor_*() to determine the largest integral power of 2 that is not greater than value.[63]
    • Add stdc_bit_ceil_*() to determine the smallest integral power of 2 that is not less than value.[63]
    • Add stdc_bit_width_*() to determine number of bits to represent a value.[63]
  • Add timegm() function in <time.h> to convert time structure into calendar time value - similar to function in glibc and musl libraries.[64]
  • New <math.h> functions based on IEEE 754-2019 recommendations, such as trigonometry functions operating on units of πx and exp10.[65]

Obsolete features

Obsolete C programming language features removed or deprecated from C23:

  • Remove trigraphs.[66]
  • Remove K&R function definitions/declarations (with no information about the function arguments).[67][68]
  • Remove representations for signed integers other than two's complement. Two's complement signed integer representation will be required.[69]
  • The Template:C-lang macros in <float.h> are obsolescent features.[70]

Compiler support

The following compilers implement an experimental compiler flag to support this standard:

Additionally, versions of GCC beyond GCC 15 now use C23 by default.[74]

Available texts

Like other editions of the C standard, the official ISO text of the standard is not freely available.

The latest working draft pre-C23 that was made public was N3096,[7] dated 2023-04-01. In the months that followed this draft, hundreds of changes[75] were made before producing the working draft N3149 dated 2023-07-09 and the official draft standard N3219 dated 2024-02-22.[75][76] Neither of these later drafts is public.[75][76]

On the same date that the draft standard N3219 was announced, a new working draft N3220[4] was made public. While this document is officially described[76] as a draft of the future version "C2Y" of the standard, the accompanying "Editor's Report" specifies that N3220 differs from the draft C23 standard N3219 only by a fix to one footnote in Annex K.[76]

See also

Template:C++ language revisions

Template:Clear

References

Template:Reflist

Further reading

  • ISO/IEC 9899:2024 (official C23 standard); ISO; 2024. (available but not free)
  • N3096 (last freely-available working draft before C23); WG14; April 2023. (free download)
  • N3149 (working draft of C23 standard); WG14; July 2023. (not available to public)
  • N3219 (ISO/IEC 9899:2023 DIS Draft); WG14; February 2024. (ISO draft available but not free)
  • N3220 (first working draft after C23; differs from draft standard N3219 only in one footnote); WG14; February 2024. (free download)

Template:Portal

Template:S-start Template:S-bef Template:S-ttl Template:S-aft Template:End

Template:C programming language

  1. ↑ Template:Cite web
  2. ↑ Template:Cite web
  3. ↑ Template:Cite web
  4. ↑ 4.0 4.1 Template:Cite web
  5. ↑ Template:Cite web
  6. ↑ Template:Cite web
  7. ↑ 7.0 7.1 Template:Cite web
  8. ↑ 8.0 8.1 Template:Cite web
  9. ↑ Template:Cite web
  10. ↑ Template:Cite web
  11. ↑ Template:Cite web
  12. ↑ Template:Cite web
  13. ↑ Template:Cite web
  14. ↑ Template:Cite web
  15. ↑ Template:Cite web
  16. ↑ Template:Cite web
  17. ↑ Template:Cite web
  18. ↑ Template:Cite web
  19. ↑ Template:Cite web
  20. ↑ Template:Cite web
  21. ↑ Template:Cite web
  22. ↑ Template:Cite web
  23. ↑ Template:Cite web
  24. ↑ Template:Cite web
  25. ↑ 25.0 25.1 25.2 Template:Cite web
  26. ↑ Template:Cite web
  27. ↑ Template:Cite web
  28. ↑ Template:Cite web
  29. ↑ Template:Cite web
  30. ↑ Template:Cite web
  31. ↑ 31.0 31.1 Template:Cite web
  32. ↑ Template:Cite web
  33. ↑ 33.0 33.1 Template:Cite web
  34. ↑ Template:Cite web
  35. ↑ Template:Cite web
  36. ↑ Template:Cite web
  37. ↑ Template:Cite web
  38. ↑ Template:Cite web
  39. ↑ Template:Cite web
  40. ↑ Template:Cite web
  41. ↑ Template:Cite web
  42. ↑ Template:Cite web
  43. ↑ Template:Cite web
  44. ↑ Template:Cite web
  45. ↑ Template:Cite web
  46. ↑ Template:Cite web
  47. ↑ Template:Cite web
  48. ↑ Template:Cite web
  49. ↑ What is the point of the UTF-8 character literals proposed for C++17?; Stack Overflow.
  50. ↑ Template:Cite web
  51. ↑ Template:Cite web
  52. ↑ Template:Cite web
  53. ↑ Template:Cite web
  54. ↑ Template:Cite web
  55. ↑ Template:Cite web
  56. ↑ 56.0 56.1 56.2 Template:Cite web
  57. ↑ Template:Cite web
  58. ↑ Template:Cite web
  59. ↑ Template:Cite web
  60. ↑ Template:Cite web
  61. ↑ Template:Cite web
  62. ↑ Template:Cite web
  63. ↑ 63.00 63.01 63.02 63.03 63.04 63.05 63.06 63.07 63.08 63.09 63.10 Template:Cite web
  64. ↑ Template:Cite web
  65. ↑ See N3096 § B.11 for a useful overview. The functions were added in separate documents: N2488, its updated versions, and its refs.
  66. ↑ Template:Cite web
  67. ↑ Template:Cite web
  68. ↑ Template:Cite web
  69. ↑ Template:Cite web
  70. ↑ Template:Cite web
  71. ↑ Template:Cite web
  72. ↑ Template:Cite web
  73. ↑ Template:Cite web
  74. ↑ Template:Cite web
  75. ↑ 75.0 75.1 75.2 Template:Cite web
  76. ↑ 76.0 76.1 76.2 76.3 Template:Cite web