gpt4 book ai didi

c - 为什么使用严格一致的程序和一致的实现并不能保证绝对的可移植性?

转载 作者:行者123 更新时间:2023-12-04 00:49:39 25 4
gpt4 key购买 nike

C11, 4. 一致性,脚注 5(添加了强调):

Strictly conforming programs are intended to be maximally portable among conforming implementations.

为什么严格符合程序&&符合实现的组合导致可移植性的分级(即最大)?

换句话说,为什么严格符合程序&&符合实现的组合不会带来绝对的可移植性?

确保绝对可移植性的障碍/挑战是什么?

最佳答案

C 标准涵盖托管和独立实现。两者之间没有(也可能)没有“绝对可移植性”。特别是对于托管实现,严格的合规性保证了可移植性,根据相同的一致性部分(C11 4.5-6):

  1. A strictly conforming program shall use only those features of the language and library specified in this International Standard. It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any minimum implementation limit.

  2. 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 in which the use of the features specified in the library clause (clause 7) is confined to [...]


[ EDIT ] 正如 @Nate Eldredge 指出的那样在下面的评论中,符合(托管)实现“ 接受 任何严格符合的程序”的声明不等于保证它将“能够翻译和执行”相同的严格符合的程序。

这是因为 5.2.4 Environmental Limits部分列出了一些最低限度,但仅要求“实现应能够 翻译和执行至少一个包含至少一个实例的程序 以下每一个限制”。

换句话说,即使严格遵守程序遵循4.5并且“不超过任何最小实现限制”,C 语言的字面意思仍然不能保证实现能够成功编译和运行它。作为@Jerry Coffin把它放在这个answer相关问题:““hello world”程序不严格符合”。

或者,正如 Derek M. Jones 在 The New C Standard 中评论的那样:

The topic of a perverse implementation, one that cansuccessfully translate a single program containing all of these limits but no other program, crops up fromtime to time. Although of theoretical interest, this discussion is of little practical interest, because writinga translator that only handled a single program would probably require more effort than writing one thathandled programs in general.

关于c - 为什么使用严格一致的程序和一致的实现并不能保证绝对的可移植性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67487230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com