免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: g050649
打印 上一主题 下一主题

C深度剖析 [复制链接]

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
251 [报告]
发表于 2012-06-21 21:47 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
252 [报告]
发表于 2012-06-21 21:59 |只看该作者
回复 267# pmerofc


    看前面的回答,这个问题讨论了好几十楼了

论坛徽章:
0
253 [报告]
发表于 2012-06-21 22:04 |只看该作者
本帖最后由 幻の上帝 于 2012-06-21 22:05 编辑

回复 260# kzl0629

很简单,这里的implementation-defined决定的只是suggestion中的哪些是effective的extent,没有涉及决定是否能拒绝接受代码的能力。

ISO C11(N1570)
6.7.1
Semantics
6 A declaration of an identifier for an object with storage-class specifier register suggests that access to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined.

而事实上,即便这里说的没有那么明确,以implementation-defined(这里只可能是指behavior而不是value)确定是否接受代码也是不可能的,除非标准明确另行规定实现可以选择接受或不接受这个代码的这两种明确选择。

ISO C11(N1570)
3.4.1
1 implementation-defined behavior
unspecified behavior where each implementation documents how the choice is made
3.4.4
1 unspecified behavior
use of an unspecified value, or other behavior where this International Standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance

ISO C中,implementation-defined behavior是unspecified behavior的子集。所以要说implementation-defined behavior,那么必然是unspecified behavior,必须给出choices。但这里没有。

从另一个角度来讲,这里无论是否接受,实现都没有义务给出诊断消息,因为这里显然不会是语法错误,上面的小标题是semantics而不是constraints:

3.8
1 constraint
restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted

5.1.1.3 Diagnostics
1 A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. Diagnostic messages need not be produced in other circumstances.9)
9) The intent is that an implementation should identify the nature of, and where possible localize, each violation. Of course, an implementation is free to produce any number of diagnostics as long as a valid program is still correctly translated. It may also successfully translate an invalid program.

剩下可以认为允许接受但不保证正确的(且不给出诊断消息的),只有undefined behavior了:

3.4.3
1 undefined behavior
behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements

但一个undefined behavior显然不是unsepcified behavior,更别提是implementation-defined behavior了:

4/3 A program that is correct in all other aspects, operating on correct data, containing unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
254 [报告]
发表于 2012-06-21 22:07 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
255 [报告]
发表于 2012-06-21 22:12 |只看该作者
回复 271# nilgod


这回是零碎的段落,截图反而麻烦。
以后要是整页的我就截图算了。

论坛徽章:
0
256 [报告]
发表于 2012-06-21 22:12 |只看该作者
回复 269# 幻の上帝


    请不要以为就你读过标准

J.3 Implementation-defined behavior
1 A conforming implementation is required to document its choice of behavior in each of
the areas listed in this subclause. The following are implementation-defined:
J.3.1 Translation
1 — How a diagnostic is identified (3.10, 5.1.1.3).

diagnostic message
message belonging to an implementation-defined subset of the implementation’s message
output

可以决定message output 你怎么解释

论坛徽章:
0
257 [报告]
发表于 2012-06-21 22:13 |只看该作者
回复 271# nilgod


另外截图以后加粗划重点什么的也麻烦了……有时候内容比较多的时候又想明确上下文,这还是必要的。

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
258 [报告]
发表于 2012-06-21 22:15 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
259 [报告]
发表于 2012-06-21 22:19 |只看该作者
回复 273# kzl0629

这只是决定output的内容和次要形式(比如说算error还是算warning,虽然习惯来说对于拒绝接受代码应该算error)。“有”和“没有”diagnostic message是另一个问题,是上面5.1.1.3的约定。
当然你也硬可以说空集也算output……这个嘛那我也没办法了。

PS.正文有替代就最好不要找Informative的Annex,上下文可以更清楚点。

论坛徽章:
0
260 [报告]
发表于 2012-06-21 22:24 |只看该作者
回复 275# pmerofc

如果说前面的一些内容是涉嫌误导,那270L和275L差不多就可以把作者的程度降到接近谭X的档次了。
出现这类低级内容错误的,根本没资格写书教育别人。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP