C11最新变化

发布于 2024-12-22 23:52:54 字数 464 浏览 1 评论 0原文

C1x 已成为 ISO/IEC 9899:2011 又名 C11。

有谁知道 2011 年 4 月草案 n1570

ETA:来自伦敦的委员会会议记录(2011 年 3 月)(应包含在 n1570 中)此处,来自华盛顿特区(2011 年 10 月)此处;我认为 DC 会议纪要中已接受的更改列表应该涵盖所有内容。

C1x has become ISO/IEC 9899:2011 aka C11.

Does anyone know what changes (if any) there are in the Standard from the April 2011 draft n1570?

ETA: There are the Committee minutes from London (March 2011) (which should be included in n1570) here, and from Washington, DC (October 2011) here; I suppose a list of accepted changes in the DC minutes should cover things.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏九 2024-12-29 23:52:54

我今天刚刚了解到 N1570 和最终的 C11 标准 (ISO/IEC 9899:2011 (E)) 之间存在一个(有些)重大变化。

在 N1570 中,6.3.2p3 说:

除非它是 sizeof 运算符的操作数,_Alignof
运算符,或一元 & 运算符,或者是用于
初始化一个数组,类型为“array of type”的表达式是
转换为类型为“指向类型的指针”的表达式
到数组对象的初始元素并且不是左值。

包含 _Alignof 是一个错误,因为一元表达式的语法允许

_Alignof ( type-name )

但不允许。

_Alignof unary-expression

已发布的 C11 标准纠正了此错误并恢复为 C99 措辞:

除非它是 sizeof 运算符的操作数,或者
一元 & 运算符,或者是用于初始化数组的字符串文字,
类型为“array of type”的表达式被转换为
类型为“指向类型”的表达式,指向初始值
数组对象的元素并且不是左值。

更多信息:ISO C 委员会成员 Larry Jones 最近在 comp.std.c 上发布了一篇有关 N1570 与已发布标准之间差异的帖子,其中写道:

其中有很多,但大多数只是轻微的编辑调整,
更改样板文本,并重新整理内容以保持
使人快乐的力量。最大的变化是从 a 中删除 _Alignof
一堆不应该添加的地方(基于错误的
它需要一个类型或一个表达式,就像 sizeof 那样
当它实际上只需要一个类型时):6.3.2.1p2、p3、p4、fn。 65;和
6.7.1 fn。 121.

消息 ID:<[电子邮件受保护]>

这是该帖子如 groups.google.com 上所示。

I just learned today that there was one (somewhat) significant change between N1570 and the final C11 standard (ISO/IEC 9899:2011 (E)).

In N1570, 6.3.2p3 says:

Except when it is the operand of the sizeof operator, the _Alignof
operator, or the unary & operator, or is a string literal used to
initialize an array, an expression that has type "array of type" is
converted to an expression with type "pointer to type" that points
to the initial element of the array object and is not an lvalue.

The inclusion of _Alignof was an error, since the syntax of a unary-expression permits

_Alignof ( type-name )

but not

_Alignof unary-expression

The released C11 standard corrects this error and reverts to the C99 wording:

Except when it is the operand of the sizeof operator, or the
unary & operator, or is a string literal used to initialize an array, an
expression that has type "array of type" is converted to an
expression with type "pointer to type" that points to the initial
element of the array object and is not an lvalue.

More information: in a recent posting to comp.std.c about differences between N1570 and the released standard, Larry Jones, a member of the ISO C committee, wrote:

There are a number of them, but most are just minor editorial tweaks,
changes to boilerplate text, and shuffling things around to keep the
powers that be happy. The biggest change was removing _Alignof from a
bunch of places it shouldn't have been added (based on the erroneous
notion that it takes either a type or an expression like sizeof does
when it really only takes a type): 6.3.2.1p2, p3, p4, fn. 65; and
6.7.1 fn. 121.

Message-ID: <[email protected]>

Here's the thread as seen on groups.google.com.

伤感在游骋 2024-12-29 23:52:54

Jens Gustedt 在评论中回答:

根据 Larry Jones 在 comp.std.c 上的评论,N1569(即没有更改标记的 N1570)没有显着变化。唯一尚未解决的问题是 __STDC_VERSION__ 的值,但我猜最自然的是它会是 201112L

Answered by Jens Gustedt in the comments:

According to a comment by Larry Jones on comp.std.c there were no significant changes from N1569 (which is N1570 without change markers). The only thing that remains unsolved is the value for __STDC_VERSION__, but I guess most naturally it will be 201112L.

人间☆小暴躁 2024-12-29 23:52:54

ISO 已批准并发布了 C 编程语言的新 C11 (C1x) 标准 ISO/IEC 9899:2011。与之前的标准 (C99) 相比的主要变化,如 C11 Wikipedia 文章,如下:

该标准包括对 C99 语言和库规范的多项更改,例如:

  • 对齐规范(_Alignas 说明符、_Alignof 运算符、aligned_alloc 函数、 标头文件)
  • _Noreturn 函数说明符
  • 使用 _Generic 关键字的类型通用表达式。例如,以下宏 cbrt(x) 转换为 cbrtl(x)cbrt(x)cbrtf(x) 取决于 x 的类型:

     #define cbrt(X) _Generic((X), long double: cbrtl, \
                                      默认值:cbrt,\
                                      浮动:cbrtf)(X)
    
  • 多线程支持(_Thread_local 存储类说明符、 标头,包括线程创建/管理函数、互斥锁、条件变量和特定于线程的存储功能,以及用于不间断对象访问的 _Atomic 类型限定符和 )。
  • 基于 C Unicode 技术报告 ISO/IEC TR 19769:2004(用于存储 UTF-16/UTF-32 编码数据的 char16_tchar32_t 类型)改进了 Unicode 支持,包括 中的转换函数以及相应的 uU 字符串文字前缀,如以及 UTF-8 编码文字的 u8 前缀)。
  • 删除了在之前的 C 语言标准修订版 ISO/IEC 9899:1999/Cor.3:2007(E) 中已弃用的 gets 函数,转而采用新的安全替代方案,<代码>gets_s。
  • 边界检查接口(附录 K)。
  • 可分析性功能(附录 L)。
  • 更多用于查询浮点类型特征的宏,涉及次正规浮点数以及该类型能够存储的小数位数。
  • 匿名结构联合,当联合和结构嵌套时有用,例如在struct T { int tag;联合{浮动x;整数 n; }; };.
  • 静态断言,当翻译者理解类型时,在翻译期间比 #if#error 稍后的阶段评估静态断言。
  • fopen 的专有创建和打开模式(“…x” 后缀)。这与 POSIX 中的 O_CREAT|O_EXCL 类似,通常用于锁定文件。
  • quick_exit 函数是终止程序的第三种方式,旨在在 exit 终止失败时至少执行最小程度的取消初始化。
  • 用于构造复数值的宏(部分原因是,如果imaginary 为无穷大或 NaN,real + imaginary*I 可能不会产生预期值)。

从 ISO 网站您可以购买完整发布的标准。以下是摘自 ISO 站点的摘要:

ISO/IEC 9899:2011 指定了用 C 编程语言编写的程序的形式并建立了解释。它指定了

  • C 程序的表示;
  • C 语言的语法和约束;
  • 解释 C 程序的语义规则;
  • 由 C 程序处理的输入数据的表示;
  • C 程序产生的输出数据的表示;
  • C 的一致性实现所施加的约束和限制。

ISO/IEC 9899:2011 未指定

  • 将 C 程序转换为数据处理系统使用的机制;
  • 数据处理系统调用 C 程序的机制;
  • 转换输入数据以供 C 程序使用的机制;
  • C 程序生成输出数据后进行转换的机制;
  • 程序及其数据的大小或复杂性将超出任何特定数据处理系统或特定处理器的能力;
  • 能够支持一致实施的数据处理系统的所有最低要求。
    ISO/IEC 9899:2011 旨在促进 C 程序在各种数据处理系统之间的可移植性。它供实现者和程序员使用。

ISO has ratified and published as ISO/IEC 9899:2011 the new C11 (C1x) standard for the C programming language. The major changes from the previous standard (C99), as written in the C11 Wikipedia article, are the following:

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 file)
  • The _Noreturn function specifier
  • 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)
    
  • Multithreading 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 the _Atomic type qualifier and <stdatomic.h> for uninterruptible object access).
  • 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).
  • Removal of the gets function, deprecated in the previous C language standard revision, ISO/IEC 9899:1999/Cor.3:2007(E), in favor of a new safe alternative, gets_s.
  • Bounds-checking interfaces (Annex K).
  • 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 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) 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 deinitializition if termination with exit fails.
  • Macros for the construction of complex values (partly because real + imaginary*I might not yield the expected value if imaginary is infinite or NaN).

From the ISO site you can buy the full published standard. Here is an abstract taken from the ISO site:

ISO/IEC 9899:2011 specifies the form and establishes the interpretation of programs written in the C programming language. It specifies

  • the representation of C programs;
  • the syntax and constraints of the C language;
  • the semantic rules for interpreting C programs;
  • the representation of input data to be processed by C programs;
  • the representation of output data produced by C programs;
  • the restrictions and limits imposed by a conforming implementation of C.

ISO/IEC 9899:2011 does not specify

  • the mechanism by which C programs are transformed for use by a data-processing system;
  • the mechanism by which C programs are invoked for use by a data-processing system;
  • the mechanism by which input data are transformed for use by a C program;
  • the mechanism by which output data are transformed after being produced by a C program;
  • the size or complexity of a program and its data that will exceed the capacity of any specific data-processing system or the capacity of a particular processor;
  • all minimal requirements of a data-processing system that is capable of supporting a conforming implementation.
    ISO/IEC 9899:2011 is designed to promote the portability of C programs among a variety of data-processing systems. It is intended for use by implementers and programmers.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文