From WikiChip
Editing c/c11

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
{{c title|C11}}{{C standards}}
+
'''C11''' is the latest major revision of the C standard ratified by ISO on December 8, 2011 by the the international standardization working group for the programming language C, ''ISO/IEC JTC1/SC22/WG14''<ref>[http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853  Information technology -- Programming languages -- C]</ref>. C11 obsoletes the previous standard, C99, published in 1999. In April of 2011 the final draft ([http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf N1570]) was published. The draft passed its final review on October 10, 2011 which was consequently ratified and published as '''ISO/IEC 9899:2011'''. C11 was also later adopted by INCITS as an ANSI standard on May 23, 2012 as '''INCITS/ISO/IEC 9899-2012'''<ref>[http://webstore.ansi.org/RecordDetail.aspx?sku=INCITS%2FISO%2FIEC+9899-2012 INCITS/ISO/IEC 9899-2012]</ref>.
'''C11''' is the latest major revision of the [[C]] standard which was ratified by ISO on December 8, 2011 by the the international standardization working group for the [[C]] programming language, ''ISO/IEC JTC1/SC22/WG14''<ref>[http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853  Information technology -- Programming languages -- C]</ref>. C11 obsoletes the previous standard, C99, published in 1999. In April of 2011 the final draft ([http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf N1570]) was published. The draft passed its final review on October 10, 2011 which was consequently ratified and published as '''ISO/IEC 9899:2011'''. C11 was also later adopted by INCITS as an ANSI standard on May 23, 2012 as '''INCITS/ISO/IEC 9899-2012'''<ref>[http://webstore.ansi.org/RecordDetail.aspx?sku=INCITS%2FISO%2FIEC+9899-2012 INCITS/ISO/IEC 9899-2012]</ref>.
 
 
 
The C11 standard adds concurrency support, provides a mechanism for {{C|generic selection|type-generic expressions}}, adds alignment-related facilities, {{C|static assertion}}, Unicode support, floating-point characteristic macros, no-return functions, anonymous structures and unions
 
, and various bound-checking and reentrancy functions.
 
 
 
== Version detection ==
 
C11 can be detected via the '''__STDC_VERSION__''' mandatory macro and the '''__STDC_LIB_EXT1__''' conditional feature macro which must equal ''201112L''. Note that the official standard has a defect where the macro's definition is set to '201ymmL'. The defect has been corrected in Defect Report [http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_411.htm #411].
 
 
 
<source lang="C">
 
#if __STDC_VERSION__ >= 201112L
 
    /* C11 support */
 
#endif
 
</source>
 
 
 
== New headers ==
 
C11 introduces 5 new [[C standard library|standard headers]]: <[[stdalign.h]]>, <[[stdatomic.h]]>, <[[stdnoreturn.h]]>, <[[threads.h]]>, and <[[uchar.h]]>. The two concerned with concurrency (stdatomic.h and threads.h) are optional.
 
 
 
== No-return functions ==
 
Some functions do not ever return for various reasons. The new '''_Noreturn''' keyword can be used to mark functions that do not return to their caller such as ''exit()'', ''longjmp()'', and ''thrd_exit()''.  Using _Noreturn can assist compiler's optimizers as well as eliminating possible diagnostic messages.
 
 
 
Note that the use of _Noreturn must be limited to functions that cannot return under any circumstance. No-return functions that may return under certain conditions will exhibit undefined behavior.
 
 
 
== Alignment ==
 
{{main|c/alignment of objects|l1=Alignment of objects}}
 
C11 provides a new mechanism for working with objects alignments. The '''_Alignof''' operator was added which yields the alignment requirement (an  integer constant) of its operand type (which remains unevaluted). A set of convenient macros such as ''alignof'' and ''alignas'' are defined in [[stdalign.h|<stdalign.h>]].
 
 
 
For example:
 
 
 
<source lang="C">printf("The alignment of char is %zd.\n", _Alignof (char));</source>
 
 
 
Which must print 1 for the alignment of char. Additionally, the alignment can be specified as an integer using the '''_Alignas''' alignment specifier.
 
 
 
On each platform, a some type has the largest alignment requirement. C11 added the '''max_align_t''' object type whose alignment is as great as is supported by the implementation.
 
 
 
=== Extended alignment ===
 
Extended alignment is the ability for an implementation to support alignment requirement greater than _Alignof (max_align_t). A type having extended alignment requirement is called an ''over-aligned type''. That feature is optional and need not be supported.
 
 
 
== Aligned memory allocations ==
 
C11 added the {{C|stdlib.h/aligned_alloc|aligned_alloc}} function which allocates space for an object whose alignment is provided by you.
 
 
 
== Unicode support ==
 
C11 adds support for Unicode characters and string literals. A set of prefixes have been added to support [[UTF-8]], [[UTF-16]], and [[UTF-32]] character strings. The ''u8'' prefix for strings creates a UTF-8 encoded string. Likewise the ''u'' and ''U''' prefixes create UTF-16 and UTF-32 strings respectively. For example:
 
 
 
<source lang="C">
 
#include <uchar.h>
 
 
 
/* UTF-8 */
 
char u8str[] = u8"ππ This is a UTF-8 string ππ.";
 
char u8chr = u8'π';
 
 
 
/* UTF-16 */
 
#ifdef __STD_UTF_16__
 
    char16_t u16str[] = u"ΩΩ This is a UTF-16 string ΩΩ.";
 
    char16_t u16char = u'Ω';
 
#endif
 
 
 
/* UTF-32 */
 
#ifdef __STD_UTF_32__
 
    char32_t u32str[] = U"δδ This is a UTF-32 string δδ.";
 
    char32_t u32char = U'δ';
 
#endif
 
</source>
 
 
 
== Type-generic expressions ==
 
{{main|c/generic selection|l1=Generic selection}}
 
C11 now provides a mechanism for type-generic expressions, a mechanism needed to perform type-generic math without compiler magic. The feature is achieved via the addition of the new '''_Generic''' keyword.
 
 
 
== Static assertion ==
 
{{main|c/static assertion|l1=Static assertion}}
 
C11 added support for compile-time assertions. Static assertions are evaluated after the preprocessor compilation phase is over, thereby allowing the use of C operators such as ''sizeof''.
 
 
 
== Bounds-checking interfaces annex (Annex K) ==
 
The Bounds-checking interfaces annex provides a set of functions with more restricted behaviors in order to allow for more secure coding practices.
 
 
 
=== Reentrant functions ===
 
The functions ''strtok_s'', ''wcstok_s'', ''bsearch_s'', and ''qsort_s'', were added, which keep track of their state via an argument that is passed instead of a static buffer to ensure they are reentrant.
 
 
 
=== %n format specifier ===
 
In various format printing functions, all %specifiers with the exception of %n are used for output purpose. On the other hand, the %n specifier is user for input. The ''_s'' version of the functions was added, which gets rid of the %n specifier entirely.
 
 
 
=== memset_s ===
 
The memset_s function is a special version of memset that must execute even if the compiler's optimizer considers it superfluous. The best case for this is when a function attempts to zero-out some confidential information such as a password right before returning, thus making the optimizer think that the memset is not doing anything.
 
 
 
== Analyzability annex (Annex L) ==
 
The Analyzability Annex identifies a small subset of all undefined behaviors and sets some implementation constraints on the resulting behavior in an attempt to mitigate potential issues. An implementation that conforms to Annex L must define '''__STDC_ANALYZABLE__'''.
 
 
 
== Concurrency ==
 
{{main|c/concurrency|l1=Concurrency}}
 
C11's largest addition to the C programming language, is the addition of semantics of multi‐threaded programs. The standard also added a facility for performing inter‐thread communication via atomic variables as well as thread-specific storage. Thread support is optional and must be tested for via the  '''__STDC_NO_THREADS__''' macro.
 
 
 
== Compiler support ==
 
 
 
{| class="wikitable"
 
|-
 
| style="background:#CCCCFF;text-align:center;" colspan="4" | C11 Compiler Support
 
|-
 
! Compiler Name !! Support Level !! style="text-align:center;" | Enforcement Switch !! Note
 
|-
 
| ACK || style="background:#FF6666;text-align:center;" | No Support || ||
 
|-
 
| Clang || style="background:#99FF66;text-align:center;" | Supported || style="text-align:center;" | -std=c11 || No support for (optional) <threads.h>
 
|-
 
| GCC || style="background:#99FF66;text-align:center;" | Supported || style="text-align:center;" | -std=c11<ref>[http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html Options Controlling C Dialect]</ref> || No support for (optional) <threads.h><ref>[http://gcc.gnu.org/wiki/C11Status C11 Status]</ref>
 
|-
 
| TCC || style="background:#FFCC66;text-align:center;" | Partial || ||
 
|-
 
| ICC || style="background:#FFCC66;text-align:center;" | Partial || style="text-align:center;" | ||
 
|-
 
| Visual C++ || style="background:#FFCC66;text-align:center;" | Partial ||  || Missing most headers
 
|}
 
  
 
== References ==
 
== References ==
 
{{reflist}}
 
{{reflist}}
 
== External links ==
 
* [http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf C11 final draft]
 
 
[[Category:C standards]]
 

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)