C11 (C standard revision)
{{Distinguish|C++11}}
{{Short description|C programming language standard, 2011 revision}}
{{C language revisions}}
C11 (previously C1X, formally ISO/IEC 9899:2011{{cite web|url=https://www.iso.org/standard/57853.html|title=ISO/IEC 9899:2011 - Information technology -- Programming languages -- C|website=www.iso.org}}) 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.{{cite web|url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1460.htm|title=Subsetting the C Standard|website=www.open-std.org}}
The final draft, N1570, 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.{{cite web|url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_411.htm|title=Defect report #411|date=February 2012|publisher=ISO/IEC JTC1/SC22/WG14 - C|access-date=2012-05-04}}
Changes from C99
The standard includes several changes to the C99 language and library specifications, such as
- 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 macrocbrt(x)
translates tocbrtl(x)
,cbrt(x)
orcbrtf(x)
depending on the type ofx
:
- 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>
{{cite web|url=http://en.cppreference.com/w/c/atomic|title=Atomic operations library - cppreference.com|website=en.cppreference.com}} 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
andchar32_t
types for storing UTF-16/UTF-32 encoded data, including conversion functions in<uchar.h>
and the correspondingu
andU
string literal prefixes, as well as theu8
prefix for UTF-8 encoded literals). - Removal of the
gets
function (in favor of saferfgets
), which was deprecated in the previous C language standard revision, ISO/IEC 9899:1999/Cor.3:2007(E). - Bounds-checking interfaces (Annex K).{{cite web|last=Berin Babcock-McConnell|title=API02-C. Functions that read or write to or from an array should take an argument to specify the source or target size|url=https://www.securecoding.cert.org/confluence/display/c/API02-C.+Functions+that+read+or+write+to+or+from+an+array+should+take+an+argument+to+specify+the+source+or+target+size}}
- 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 {{code|2=c|struct T { int tag; union { float x; int n; }; };}}.
- 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) forfopen
. This behaves likeO_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.{{cite web|url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1327.htm|title=Abandoning a Process|website=www.open-std.org}} - 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 ifimaginary
is infinite or NaN).
Optional features
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. Programs can use predefined macros to determine whether an implementation supports a certain feature or not.
class="wikitable sortable"
|+ Optional features in C11 ! Feature ! Feature test macro |
Analyzability (Annex L)
| | {{no|Not available}} |
Bounds-checking interfaces (Annex K)
| | {{no|Not available}} |
Multithreading (<threads.h> )
| | {{no|Not available}} |
Atomic primitives and types (<stdatomic.h> and the _Atomic type qualifier){{cite web|url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1558.pdf|title=WG14 N1558 Mar 14-18 meeting minutes (draft)}}
| | {{no|Not available}} |
IEC 60559 floating-point arithmetic (Annex F)
| | {{partial|Optional}} |
IEC 60559 compatible complex arithmetic (Annex G)
| | {{partial|Optional}} |
Complex types (<complex.h> )
| | {{yes|Mandatory for hosted implementations}} |
Variable-length arraysISO 9899:2011 Programming Languages - C 6.7.6.2 4
| | {{yes|Mandatory}} |
Compiler support
Some features of C11 are supported by the GCC starting with version 4.6,{{cite web|url=https://gcc.gnu.org/gcc-4.6/changes.html#c|title=GCC 4.6 Release Series — Changes, New Features, and Fixes - GNU Project - Free Software Foundation (FSF)|website=gcc.gnu.org}} Clang starting with version 3.1,{{cite web|url=http://llvm.org/releases/3.1/docs/ClangReleaseNotes.html#cchanges|title=Clang 3.1 Release Notes|website=llvm.org}} IBM XL C starting with version 12.1,{{cite web|url=http://www.ibm.com/developerworks/rational/library/support-iso-c11/index.html|title=Support for ISO C11 added to IBM XL C/C++ compilers|date=17 April 2014|website=www.ibm.com}} and Microsoft Visual C++ starting with VS 2019 (16.8){{cite web|url=https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/|title=C11 and C17 Standard Support Arriving in MSVC|date=14 September 2020|website=devblogs.microsoft.com}} in September 2020.
Criticism
{{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. Even Microsoft, a main proponent of this interface, does not conform to the definition.{{cite web |last1=Leffler |first1=Jonathan |title=c - Do you use the TR 24731 'safe' functions? |url=https://stackoverflow.com/a/373911 |website=Stack Overflow}} In addition, Annex K does not include the more useful TR24731-2 (dynamic allocation functions), such as {{code|vasprintf}} and {{code|open_memstream}}.{{cite web |title=c - Do you use the TR 24731 'safe' functions? |url=https://stackoverflow.com/a/17353714 |website=Stack Overflow}} The few open-source implementations include Open Watcom C/C++'s "Safer C" library{{cite web|url=http://openwatcom.org/index.php/Safer_C_Library|title=Safer C Library - Open Watcom|date=3 May 2015|archive-url=https://web.archive.org/web/20150503192244/http://openwatcom.org/index.php/Safer_C_Library|archive-date=2015-05-03}} and safeclib.{{cite web |title=safec: Safe C Library - README |url=https://rurban.github.io/safeclib/doc/safec-3.5.2/index.html |website=rurban.github.io}}
See also
References
Further reading
- [https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf N1570] (working draft of C11 standard); WG14; 2011. ([https://port70.net/~nsz/c/c11 HTML and ASCII versions])
- [https://www.iso.org/standard/57853.html ISO/IEC 9899:2011] (official C11 standard); ISO; 2011.
- {{cite journal|last=Plum|first=Thomas|date=April 6, 2012|title=C Finally Gets A New Standard|journal=Dr. Dobb's Journal|url=http://drdobbs.com/cpp/232800444}}
- [https://web.archive.org/web/20131203031224/http://www.owasp.org.cn/OWASP_Conference/2011/17_.pdf Safe C API—Concise solution of buffer overflow, The OWASP Foundation, OWASP AppSec, Beijing 2011 ]
External links
- [https://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log.htm C Language Working Group 14 (WG14) Documents]
- [http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1250.pdf C1X Charter] - WG14
- Safe C Library of Bounded APIs
{{S-start}}
{{S-bef| before = C99}}
{{S-ttl| title=C language standards}}
{{S-aft| after = C17}}
{{end}}
{{C programming language}}
{{ISO standards}}
Category:C (programming language)