C11 (C Standard Revision) - Wikipedia

Có thể bạn quan tâm

Not to be confused with C++11. C programming language standard, 2011 revision
C language revisions
  • K&R C
  • ANSI C
  • C99
  • C11
  • C17
  • C23
  • v
  • t
  • e

C11 (previously C1X, formally ISO/IEC 9899:2011),[1] is a past standard for the C programming language. It replaced C99 (standard ISO/IEC 9899:1999) and has been superseded by C17 (standard ISO/IEC 9899:2018). C11 mainly standardizes features already supported by common contemporary compilers, and includes a detailed memory model to better support multiple threads of execution. Due to delayed availability of conforming C99 implementations, C11 makes certain features optional, to make it easier to comply with the core language standard.[2][3]

The final draft, N1570,[4] was published in April 2011. The new standard passed its final draft review on October 10, 2011 and was officially ratified by ISO and published as ISO/IEC 9899:2011 on December 8, 2011, with no comments requiring resolution by participating national bodies.

A standard macro __STDC_VERSION__ is defined with value 201112L to indicate that C11 support is available.[5]

Changes from C99

[edit]

The standard includes several changes to the C99 language and library specifications, such as[6]

  • Alignment specification (_Alignas specifier, _Alignof operator, aligned_alloc function, <stdalign.h> header)
  • The _Noreturn function specifier and the <stdnoreturn.h> header
  • Type-generic expressions using the _Generic keyword. For example, the following macro cbrt(x) translates to cbrtl(x), cbrt(x) or cbrtf(x) depending on the type of x:
#define cbrt(x) _Generic((x), long double: cbrtl, \ default: cbrt, \ float: cbrtf)(x)
  • Multi-threading support (_Thread_local storage-class specifier, <threads.h> header including thread creation/management functions, mutex, condition variable and thread-specific storage functionality, as well as <stdatomic.h>[7] for atomic operations supporting the C11 memory model).
  • Improved Unicode support based on the C Unicode Technical Report ISO/IEC TR 19769:2004 (char16_t and char32_t types for storing UTF-16/UTF-32 encoded data, including conversion functions in <uchar.h> and the corresponding u and U string literal prefixes, as well as the u8 prefix for UTF-8 encoded literals).[8]
  • Removal of the gets function (in favor of safer fgets), which was deprecated in the previous C language standard revision, ISO/IEC 9899:1999/Cor.3:2007(E).
  • Bounds-checking interfaces (Annex K).[9]
  • Analyzability features (Annex L).
  • More macros for querying the characteristics of floating-point types, concerning subnormal floating-point numbers and the number of decimal digits the type is able to store.
  • Anonymous structures and unions, useful when unions and structures are nested, e.g. in structT{inttag;union{floatx;intn;};};.
  • Static assertions, which are evaluated during translation at a later phase than #if and #error, when types are understood by the translator.
  • An exclusive create-and-open mode ("…x" suffix) for fopen. This behaves like O_CREAT|O_EXCL in POSIX, which is commonly used for lock files.
  • The quick_exit function as a third way to terminate a program, intended to do at least minimal deinitialization.[10]
  • A new timespec_get function and corresponding structure in <time.h> with a degree of POSIX compatibility.
  • Macros for the construction of complex values (partly because real + imaginary*I might not yield the expected value if imaginary is infinite or NaN).[11]

Optional features

[edit]

The new revision allows implementations to not support certain parts of the standard — including some that had been mandatory to support in the 1999 revision.[12] Programs can use predefined macros to determine whether an implementation supports a certain feature or not.

Optional features in C11
Feature Feature test macro Availability in C99[13]
Analyzability (Annex L) __STDC_ANALYZABLE__ Not available
Bounds-checking interfaces (Annex K) __STDC_LIB_EXT1__ Not available
Multithreading (<threads.h>) __STDC_NO_THREADS__ Not available
Atomic primitives and types (<stdatomic.h> and the _Atomic type qualifier)[14] __STDC_NO_ATOMICS__ Not available
IEC 60559 floating-point arithmetic (Annex F) __STDC_IEC_559__ Optional
IEC 60559 compatible complex arithmetic (Annex G) __STDC_IEC_559_COMPLEX__ Optional
Complex types (<complex.h>) __STDC_NO_COMPLEX__ Mandatory for hosted implementations
Variable-length arrays[15] __STDC_NO_VLA__ Mandatory

Compiler support

[edit]

Some features of C11 are supported by the GCC starting with version 4.6,[16] Clang starting with version 3.1,[17] IBM XL C starting with version 12.1,[18] and Microsoft Visual C++ starting with VS 2019 (16.8)[19] in September 2020.

Criticism

[edit] See also: C string handling § Replacements

The optional bounds-checking interfaces (Annex K) remain controversial and have not been widely implemented, and their deprecation or removal from the next standard revision has been proposed.[20] Even Microsoft, a main proponent of this interface, does not conform to the definition.[21] In addition, Annex K does not include the more useful TR24731-2 (dynamic allocation functions), such as vasprintf and open_memstream.[22] The few open-source implementations include Open Watcom C/C++'s "Safer C" library[23] and safeclib.[24]

See also

[edit]
  • iconComputer programming portal
  • C++23, C++20, C++17, C++14, C++11, C++03, C++98, versions of the C++ programming language standard
  • Compatibility of C and C++

References

[edit]
  1. ^ "ISO/IEC 9899:2011 - Information technology -- Programming languages -- C". www.iso.org.
  2. ^ "WG14 N1250 The C1X Charter" (PDF).
  3. ^ "Subsetting the C Standard". www.open-std.org.
  4. ^ WG14 N1570 Committee Draft — April 12, 2011
  5. ^ "Defect report #411". ISO/IEC JTC1/SC22/WG14 - C. February 2012. Retrieved 2012-05-04.
  6. ^ WG14 N1516 Committee Draft — October 4, 2010
  7. ^ "Atomic operations library - cppreference.com". en.cppreference.com.
  8. ^ "WG14 N1286 — "On Support for TR-19769 and New Character Types", Nick Stoughton, Larry Dwyer" (PDF).
  9. ^ Berin Babcock-McConnell. "API02-C. Functions that read or write to or from an array should take an argument to specify the source or target size".
  10. ^ "Abandoning a Process". www.open-std.org.
  11. ^ "Creation of complex value". www.open-std.org.
  12. ^ WG14 N1548 Committee Draft — December 2, 2010 6.10.8.3 Conditional feature macros
  13. ^ ISO 9899:1999 6.10.8 Predefined macro names
  14. ^ "WG14 N1558 Mar 14-18 meeting minutes (draft)" (PDF).
  15. ^ ISO 9899:2011 Programming Languages - C 6.7.6.2 4
  16. ^ "GCC 4.6 Release Series — Changes, New Features, and Fixes - GNU Project - Free Software Foundation (FSF)". gcc.gnu.org.
  17. ^ "Clang 3.1 Release Notes". llvm.org.
  18. ^ "Support for ISO C11 added to IBM XL C/C++ compilers". www.ibm.com. 17 April 2014.
  19. ^ "C11 and C17 Standard Support Arriving in MSVC". devblogs.microsoft.com. 14 September 2020.
  20. ^ "N1969 — Updated Field Experience With Annex K — Bounds Checking Interfaces". www.open-std.org.
  21. ^ Leffler, Jonathan. "c - Do you use the TR 24731 'safe' functions?". Stack Overflow.
  22. ^ "c - Do you use the TR 24731 'safe' functions?". Stack Overflow.
  23. ^ "Safer C Library - Open Watcom". 3 May 2015. Archived from the original on 2015-05-03.
  24. ^ "safec: Safe C Library - README". rurban.github.io.

Further reading

[edit]
  • N1570 (working draft of C11 standard); WG14; 2011. (HTML and ASCII versions)
  • ISO/IEC 9899:2011 (official C11 standard); ISO; 2011.
  • Plum, Thomas (April 6, 2012). "C Finally Gets A New Standard". Dr. Dobb's Journal.
  • Safe C API—Concise solution of buffer overflow, The OWASP Foundation, OWASP AppSec, Beijing 2011
[edit]
  • C Language Working Group 14 (WG14) Documents
  • C1X Charter - WG14
  • Safe C Library of Bounded APIs
Preceded byC99 C language standards Succeeded byC17
  • v
  • t
  • e
C programming language
  • ANSI C
  • C99
  • C11
  • C17
  • C23
  • Embedded C
  • MISRA C
Features
  • Functions
  • Header files
  • Operators
  • String
  • Syntax
  • Preprocessor
  • Data types
Standard library
  • Char
  • File I/O
  • Math
  • Dynamic memory
  • String
  • Time
  • Variadic
  • POSIX
Implementations
  • Bionic
    • libhybris
  • dietlibc
  • glibc
    • EGLIBC
  • klibc
  • Windows CRT
  • musl
  • Newlib
  • uClibc
Compilers
  • ACK
  • Borland Turbo C
  • Clang
  • GCC
  • ICC
  • LCC
  • Norcroft C
  • PCC
  • SDCC
  • TCC
  • Visual Studio, Express, C++
  • Watcom C/C++
IDEs
  • Anjuta
  • CLion
  • Code::Blocks
  • CodeLite
  • Eclipse
  • Geany
  • GNOME Builder
  • KDevelop
  • Visual Studio
  • NetBeans
Comparison withother languages
  • Compatibility of C and C++
  • Comparison with Pascal
Descendantlanguages
  • C++
  • C#
  • D
  • Objective-C
  • Alef
  • Limbo
  • Go
  • Vala
Designer
  • Dennis Ritchie
  • Category
  • v
  • t
  • e
ISO standards by standard number
List of ISO standards – ISO romanizations – IEC standards
1–9999
  • 1
  • 2
  • 3
  • 4
  • 6
  • 7
  • 9
  • 16
  • 17
  • 31
    • -0
    • -1
    • -3
    • -4
    • -5
    • -6
    • -7
    • -8
    • -9
    • -10
    • -11
    • -12
    • -13
  • 68-1
  • 128
  • 216
  • 217
  • 226
  • 228
  • 233
  • 259
  • 261
  • 262
  • 302
  • 306
  • 361
  • 500
  • 518
  • 519
  • 639
    • -1
    • -2
    • -3
    • -5
    • -6
  • 646
  • 657
  • 668
  • 690
  • 704
  • 732
  • 764
  • 838
  • 843
  • 860
  • 898
  • 965
  • 999
  • 1000
  • 1004
  • 1007
  • 1073-1
  • 1073-2
  • 1155
  • 1413
  • 1538
  • 1629
  • 1745
  • 1989
  • 2014
  • 2015
  • 2022
  • 2033
  • 2047
  • 2108
  • 2145
  • 2146
  • 2240
  • 2281
  • 2533
  • 2709
  • 2711
  • 2720
  • 2788
  • 2848
  • 2852
  • 2921
  • 3029
  • 3103
  • 3166
    • -1
    • -2
    • -3
  • 3297
  • 3307
  • 3601
  • 3602
  • 3864
  • 3901
  • 3950
  • 3977
  • 4031
  • 4157
  • 4165
  • 4217
  • 4909
  • 5218
  • 5426
  • 5427
  • 5428
  • 5725
  • 5775
  • 5776
  • 5800
  • 5807
  • 5964
  • 6166
  • 6344
  • 6346
  • 6373
  • 6385
  • 6425
  • 6429
  • 6438
  • 6523
  • 6709
  • 6943
  • 7001
  • 7002
  • 7010
  • 7027
  • 7064
  • 7098
  • 7185
  • 7200
  • 7498
    • -1
  • 7637
  • 7736
  • 7810
  • 7811
  • 7812
  • 7813
  • 7816
  • 7942
  • 8000
  • 8093
  • 8178
  • 8217
  • 8373
  • 8501-1
  • 8571
  • 8583
  • 8601
  • 8613
  • 8632
  • 8651
  • 8652
  • 8691
  • 8805/8806
  • 8807
  • 8820-5
  • 8859
    • -1
    • -2
    • -3
    • -4
    • -5
    • -6
    • -7
    • -8
    • -8-I
    • -9
    • -10
    • -11
    • -12
    • -13
    • -14
    • -15
    • -16
  • 8879
  • 9000/9001
  • 9036
  • 9075
  • 9126
  • 9141
  • 9227
  • 9241
  • 9293
  • 9314
  • 9362
  • 9407
  • 9496
  • 9506
  • 9529
  • 9564
  • 9592/9593
  • 9594
  • 9660
  • 9797-1
  • 9897
  • 9899
  • 9945
  • 9984
  • 9985
  • 9995
10000–19999
  • 10006
  • 10007
  • 10116
  • 10118-3
  • 10160
  • 10161
  • 10165
  • 10179
  • 10206
  • 10218
  • 10279
  • 10303
    • -11
    • -21
    • -22
    • -28
    • -238
  • 10383
  • 10585
  • 10589
  • 10628
  • 10646
  • 10664
  • 10746
  • 10861
  • 10957
  • 10962
  • 10967
  • 11073
  • 11170
  • 11172
  • 11179
  • 11404
  • 11544
  • 11783
  • 11784
  • 11785
  • 11801
  • 11889
  • 11898
  • 11940 (-2)
  • 11941
  • 11941 (TR)
  • 11992
  • 12006
  • 12052
  • 12182
  • 12207
  • 12234-2
  • 12620
  • 13211
    • -1
    • -2
  • 13216
  • 13250
  • 13399
  • 13406-2
  • 13450
  • 13485
  • 13490
  • 13567
  • 13568
  • 13584
  • 13616
  • 13816
  • 13818
  • 14000
  • 14031
  • 14224
  • 14289
  • 14396
  • 14443
  • 14496
    • -2
    • -3
    • -6
    • -10
    • -11
    • -12
    • -14
    • -17
    • -20
  • 14617
  • 14644
  • 14649
  • 14651
  • 14698
  • 14764
  • 14882
  • 14971
  • 15022
  • 15189
  • 15288
  • 15291
  • 15398
  • 15408
  • 15444
    • -3
    • -9
  • 15445
  • 15438
  • 15504
  • 15511
  • 15686
  • 15693
  • 15706
    • -2
  • 15707
  • 15897
  • 15919
  • 15924
  • 15926
  • 15926 WIP
  • 15930
  • 15938
  • 16023
  • 16262
  • 16355-1
  • 16485
  • 16612-2
  • 16750
  • 16949 (TS)
  • 17024
  • 17025
  • 17100
  • 17203
  • 17369
  • 17442
  • 17506
  • 17799
  • 18004
  • 18014
  • 18181
  • 18245
  • 18629
  • 18916
  • 19005
  • 19011
  • 19092
    • -1
    • -2
  • 19114
  • 19115
  • 19125
  • 19136
  • 19407
  • 19439
  • 19500
  • 19501
  • 19502
  • 19503
  • 19505
  • 19506
  • 19507
  • 19508
  • 19509
  • 19510
  • 19600
  • 19752
  • 19757
  • 19770
  • 19775-1
  • 19794-5
  • 19831
20000–29999
  • 20000
  • 20022
  • 20121
  • 20400
  • 20802
  • 20830
  • 21000
  • 21001
  • 21047
  • 21122
  • 21500
  • 21827
  • 22000
  • 22275
  • 22300
  • 22301
  • 22395
  • 22537
  • 23000
  • 23003
  • 23008
  • 23009
  • 23090-3
  • 23092
  • 23094-1
  • 23094-2
  • 23270
  • 23271
  • 23360
  • 23941
  • 24517
  • 24613
  • 24617
  • 24707
  • 24728
  • 25178
  • 25964
  • 26000
  • 26262
  • 26300
  • 26324
  • 27000 series
  • 27000
  • 27001
  • 27002
  • 27005
  • 27006
  • 27729
  • 28000
  • 29110
  • 29148
  • 29199-2
  • 29500
30000+
  • 30170
  • 31000
  • 32000
  • 37001
  • 38500
  • 39075
  • 40500
  • 42010
  • 45001
  • 50001
  • 55000
  • 56000
  • 80000
  • Category

Từ khóa » C C11