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

标签 c compiler-construction standards freestanding

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

  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

最佳答案

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 为宽字符和多字节字符集添加了新的 header 和函数,因此它包含真正的新标准 Material 。技术勘误修复了标准措辞中的问题,澄清了需要澄清的内容,并纠正了文档中的技术错误。

所以,我建议这四种模式就足够了:

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

或者,如果我们要关注导致千年问题的错误,那么:

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

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

<小时/>

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

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

有一个额外的宏/函数,va_copy() ,添加到<stdarg.h>在 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.

<小时/>

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

托管实现面临更多问题,因为库支持在 C90 和 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?

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

关于c - 独立实现的各种 WG14 C 标准之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8682465/

相关文章:

c++ - C POSIX API 是否与 C++ STL 兼容

c - 简单的C程序。从函数返回的字符串导致错误

c - 传递指针到指针的问题

c++ - 由下划线开头的标识符导致的错误的真实示例

c++ - VC15中属性的使用

c - 这段代码在 Windows 上给了我未定义的行为,但在 Linux 上运行良好

c - x86 addl 与 subl

c++ - 使用 clang 编译 C++ 文件时出错

java - 从 java 代码运行 .class 文件

实现是否可以指定未定义的行为