免费注册 查看新帖 |

Chinaunix

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

[C] 这个谁解释一下 [复制链接]

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

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

论坛徽章:
0
13 [报告]
发表于 2012-09-17 14:05 |只看该作者
我刚来的回复 11# pmerofc


   

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

论坛徽章:
0
15 [报告]
发表于 2012-09-17 17:11 |只看该作者
Annex C
(informative)
Sequence points
1The following are the sequence points described in 5.1.2.3:
—The call to a function, after the arguments have been evaluated (6.5.2.2).
—The end of the first operand of the following operators: logical AND && (6.5.13);
logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17).
—The end of a full declarator: declarators (6.7.5);
—The end of a full expression: an initializer (6.7.; the expression in an expression
statement (6.8.3); the controlling expression of a selection statement (if or switch)
(6.8.4); the controlling expression of a while or do statement (6.8.5); each of the
expressions of a for statement (6.8.5.3); the expression in a return statement
(6.8.6.4).
—Immediately before a library function returns (7.1.4).
—After the actions associated with each formatted input/output function conversion
specifier (7.19.6, 7.24.2).
—Immediately before and immediately after each call to a comparison function, and
also between anycall to a comparison function and anymovement of the objects
passed as arguments to that call (7.20.5).


由此看出,这个表达式在一对顺序点之间改变了a两次,因此是个C语言根本没定义的操作,换言之:是错误的。

论坛徽章:
0
16 [报告]
发表于 2012-09-17 17:11 |只看该作者
int a=0;
a = (++a)+(++a)+(++a)+(++a);
据我了解,似乎很多公司都有出这种笔试题的恶趣味。答案应该是Undefined,我甚至有些怀疑出
题人是否真的知道答案。下面我来解释为什么是Undefined

我们知道,调用一个函数可能产生Side Effect ,使用某些运算符(++ -- = 复合赋值)也会产生Side
Effect,如果一个表达式中隐含着多个Side Effect ,究竟哪个先发生哪个后发生呢?C 标准规定代码
中的某些点是Sequence Point,当执行到一个Sequence Point时,在此之前的Side Effect 必须全部
作用完毕,在此之后的Side Effect 必须一个都没发生。至于两个Sequence Point之间的多个Side
Effect哪个先发生哪个后发生则没有规定,编译器可以任意选择各Side Effect 的作用顺序。下面详
细解释各种Sequence Point

论坛徽章:
0
17 [报告]
发表于 2012-09-17 17:12 |只看该作者
我只所以问一下,主要是没看明白他解释的是什么。
你能更通谷的解释一下吗?

论坛徽章:
0
18 [报告]
发表于 2012-09-17 17:13 |只看该作者
C里面的标准是怎么说的,我才是我想问的

论坛徽章:
0
19 [报告]
发表于 2012-09-17 17:13 |只看该作者
回复 15# wufan110
不要引用英文原文,看不懂的


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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP