独立实施的各种 WG14 C 标准之间有什么区别?

发布于 2024-12-23 12:42:06 字数 662 浏览 1 评论 0原文

实现以下每个不同标准的独立部分的编译器有何不同?支持所有模式所需的最少数量的模式(例如,由命令行标志指定)是多少?

  1. ISO/IEC 9899
  2. :1990 ISO/IEC 9899:1990 + ISO/IEC 9899 TCOR1
  3. ISO/IEC 9899:1990 + ISO/IEC 9899 TCOR1 + ISO/IEC 9899 AM1
  4. ISO/IEC 9899:1990 + ISO/IEC 9899 TCOR1 + ISO /IEC 9899 AM1 + ISO/IEC 9899 TCOR2
  5. ISO/IEC 9899:1999
  6. ISO/IEC 9899:1999 + ISO/IEC 9899:1999 Cor. 1:2001(E)
  7. ISO/IEC 9899:1999 + ISO/IEC 9899:1999 Cor. 1:2001(E) + ISO/IEC 9899:1999 Cor. 2:2004(E)
  8. ISO/IEC 9899:1999 + ISO/IEC 9899:1999 Cor。 1:2001(E) + ISO/IEC 9899:1999 Cor. 2:2004(E) + ISO/IEC 9899:1999 Cor. 3:2007(E)
  9. ISO/IEC 9899:2011

How would compilers implementing the freestanding portion of each different standard below have to differ? What would be the fewest number of modes (specified by command line flags, for example) required to support all of them?

  1. ISO/IEC 9899:1990
  2. ISO/IEC 9899:1990 + ISO/IEC 9899 TCOR1
  3. ISO/IEC 9899:1990 + ISO/IEC 9899 TCOR1 + ISO/IEC 9899 AM1
  4. ISO/IEC 9899:1990 + ISO/IEC 9899 TCOR1 + ISO/IEC 9899 AM1 + ISO/IEC 9899 TCOR2
  5. ISO/IEC 9899:1999
  6. ISO/IEC 9899:1999 + ISO/IEC 9899:1999 Cor. 1:2001(E)
  7. ISO/IEC 9899:1999 + ISO/IEC 9899:1999 Cor. 1:2001(E) + ISO/IEC 9899:1999 Cor. 2:2004(E)
  8. ISO/IEC 9899:1999 + ISO/IEC 9899:1999 Cor. 1:2001(E) + ISO/IEC 9899:1999 Cor. 2:2004(E) + ISO/IEC 9899:1999 Cor. 3:2007(E)
  9. ISO/IEC 9899:2011

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

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

发布评论

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

评论(1

镜花水月 2024-12-30 12:42:06

TC(技术勘误或技术更正)应被视为相应基本标准的一部分。因此,您实际上有 4 个可能的标准需要处理:

  1. ISO/IEC 9899:1990 以及 TC。
  2. ISO/IEC 9899:1990 + AM1(有效为 9899:1995)加上 TC。
  3. ISO/IEC 9899:1999 以及 TC。
  4. ISO/IEC 9899:2011

C90 修正案 1 为宽字符和多字节字符集添加了新的标头和函数,因此它包含真正的新标准材料。技术勘误修复了标准措辞中的问题,澄清了需要澄清的内容,并纠正了文件中的技术错误。

因此,我建议这四种模式就足够了:

  • -std=c90
  • -std=c95
  • -std=c99
  • - std=c11

或者,如果我们要注意导致 Y2K 问题的错误,那么:

  • -std=c1990
  • -std=c1995
  • -std=c1999
  • -std=c2011

(这样做的一个好处是最新标准再次拥有最高的数字! )


对于独立实现,所需的四个标头几乎没有什么区别:

中添加了一个额外的宏/函数 va_copy() C99 中的

更正

我刚刚检查了C99的相关部分,在C99中独立实现需要一些额外的头文件:

§4 一致性

¶6 两种形式的一致性实现是托管独立式的。 合格的
托管实施应接受任何严格符合的程序。一个合格的
独立实施应接受任何严格遵守的程序,但不
使用复杂类型并在其中使用库子句中指定的功能
(第 7 条)仅限于标准标头 的内容,
;
。符合要求的实现可能有扩展(包括额外的
库函数),只要它们不改变任何严格遵守的行为
程序。3)

3) 这意味着一致的实现除了明确的标识符之外不保留任何标识符
本国际标准保留。

§5.1.2.1 独立环境

¶1 在独立环境中(其中 C 程序执行可以在没有任何
操作系统的好处),程序中调用的函数的名称和类型
启动是实现定义的。任何可供独立使用的图书馆设施
程序,除了第 4 条要求的最小集之外,都是实现定义的。

¶2 独立环境中程序终止的效果是由实现定义的。


否则,主要变化发生在C99 中的核心语言 - 新类型 (long long)、新初始化符号和 VLA 等。从这个角度来看,AM1(C95)没有对独立实现进行任何更改(除非随后添加了二合字母),因为主要的更改是在独立实现中不需要的新标头中。

托管实现面临更多问题,因为库支持在 C90 和 C99 之间进行了相当广泛的修改。


独立实现的任何更改是否会破坏向后兼容性?换句话说,如果我有一个严格独立的符合 C{1990,1995,1999} 规范的程序,它是否一定能在符合规范的 C11 实现上按预期进行编译和工作?

我不知道独立实现与托管实现相比有任何向后兼容性问题。在 C99 中,“隐式 int”规则正式消失 - 您应该在使用函数之前声明它们,并且返回类型应显式为 int (因此,例如,一个简单的main() 不再正式有效;您应该编写 int main() 或更好的 int main(void) 或类似内容。但这些是 C90 (C95) 和 C99 之间的一般变化 - 并不是独立实现所特有的。 (是的,我知道独立实现不需要函数 main() 作为起点。)如果您的代码是“好的”并且在使用之前使用原型声明或定义了函数,并且没有隐式 int 类型(强烈建议使用原型表示法定义的所有函数),那么对 C90 独立程序有利的东西也适用于 C99 或 C11。

The TCs (technical corrigenda or technical corrections) should be treated as part of the corresponding base standard. So, you really have 4 possible standards to deal with:

  1. ISO/IEC 9899:1990 plus TCs.
  2. ISO/IEC 9899:1990 + AM1 (effectively 9899:1995) plus TCs.
  3. ISO/IEC 9899:1999 plus TCs.
  4. ISO/IEC 9899:2011

The Amendment 1 for C90 added new headers and functions for wide character and multi-byte character sets, so it contained truly new standard material. The technical corrigenda fix issues in the standard wording, clarifying what needs to be clarified, and correcting technical errors in the document.

So, I would suggest that those four modes would be sufficient:

  • -std=c90
  • -std=c95
  • -std=c99
  • -std=c11

Or, if we are going to pay attention to the mistakes that led to the Y2K problems, then:

  • -std=c1990
  • -std=c1995
  • -std=c1999
  • -std=c2011

(One advantage of this is that the newest standard has the highest number once more!)


For freestanding implementations, there are few differences in the four headers that are required:

  • <stddef.h>
  • <limits.h>
  • <float.h>
  • <stdarg.h>

There was an extra macro/function, va_copy(), added to <stdarg.h> in C99.

Correction

I just checked the relevant parts of C99, and there are a number of extra headers required for a freestanding implementation in C99:

§4 Conformance

¶6 The two forms of conforming implementation are hosted and freestanding. A conforming
hosted implementation shall accept any strictly conforming program. A conforming
freestanding implementation shall accept any strictly conforming program that does not
use complex types and in which the use of the features specified in the library clause
(clause 7) is confined to the contents of the standard headers <float.h>,
<iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and
<stdint.h>. A conforming implementation may have extensions (including additional
library functions), provided they do not alter the behavior of any strictly conforming
program.3)

3) This implies that a conforming implementation reserves no identifiers other than those explicitly
reserved in this International Standard.

§5.1.2.1 Freestanding environment

¶1 In a freestanding environment (in which C program execution may take place without any
benefit of an operating system), the name and type of the function called at program
startup are implementation-defined. Any library facilities available to a freestanding
program, other than the minimal set required by clause 4, are implementation-defined.

¶2 The effect of program termination in a freestanding environment is implementation defined.


Otherwise, the main changes occurred in the core language in C99 - things like the new types (long long), new initialization notations, and VLAs, and so on. From this perspective, AM1 (C95) didn't change anything for a freestanding implementation (unless digraphs were added then) because the main changes were in new headers that are not required in a freestanding implementation.

Hosted implementations face many more issues because the library support was fairly extensively modified between C90 and C99.


Did any of the changes for freestanding implementations break backwards compatability? In other words, if I have a strictly freestanding C{1990,1995,1999} conforming program, will it necessarily compile and work as expected on a conforming C11 implementation?

I'm not aware of any backwards compatibility issues for freestanding as opposed to hosted implementations. With C99, the 'implicit int' rules are officially gone - you should declare functions before using them and the return type should be explicitly int (so, for example, a simple main() is no longer officially valid; you should write int main() or, better, int main(void) or similar). But these are general changes between C90 (C95) and C99 - not peculiar to freestanding implementations. (And yes, I am aware that a freestanding implementation need not require a function main() as the start point.) If your code is 'good' and has functions declared or defined with prototypes before use and no implicit int types (and all functions defined using prototype notation would be strongly recommended), then what was good for a C90 freestanding program will work for C99 or C11.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文