是具有任何序列点问题,这个计划? [英] Is this program having any sequence point issues?

查看:188
本文介绍了是具有任何序列点问题,这个计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #包括LT&;&stdio.h中GT;
 诠释的main()
 {
       INT I = 7,J;
       J =(我+ +,++ I,J * I);
       返回0;
}

J =(i ++,++ I,J * I);这是良好定义?让我清楚我的疑问。


解决方案

这前pression是可以的,因为的逗号运算符是一个序列点

 (我+ +,++ I,J * I)

但不与其中逗号不作为序列点以下混淆:

  somefunction(我+ +,++ I,J * I)



  

有关J = ++什么* ++ I


乘法运算符是不是一个序列点。


对不起劫持你的答案的)

从ISO的§3.49899:1999(C标准):


  

3.4的行为


  
  

外观或动作


  
  

3.4.1实现定义


  
  

未指定的行为,其中每个文件执行的选择是如何制造


  
  

例的的实现定义行为的例子是高位的传播
  当一个有符号整数被右移。


  
  

3.4.2区域设置特定的行为


  
  

行为取决于民族,文化的本地习惯和语言,每个
  执行文件


  
  

实例的区域设置特定行为的一个例子是islower判断函数是否为返回true
  人物比26小写拉丁字母等。


  
  

3.4.3未定义行为


  
  

行为,或者在错误数据的使用不可移植的或错误的程序构造,
  对于这本国际标准并没有规定要求


  
  

请注意可能的不确定的行为从与联合国predictable完全无视的情况范围
  结果,在的一个记录方式的特点翻译或程序执行过程中的行为
  环境(有或没有发出一个诊断消息),以终止翻译或
  执行(并出具诊断消息)。


  
  

实例未定义行为的一个例子是在整数溢出的行为。


  
  

3.4.4不确定的行为


  
  

行为,其中本国际标准提供了两个或更多的可能性和
  规定了这是选择在任何情况下没有进一步的要求。


  
  

实例中未指定的行为的一个例子是在该函数参数的顺序
  评估。


#include<stdio.h>
 int main()
 {  
       int i=7,j;
       j=(i++,++i,j*i); 
       return 0;
}

j=(i++,++i,j*i);Is this well defined ? Let me clear my doubt.

解决方案

This expression is OK because the comma operator is a sequence point:

(i++, ++i, j*i)

However do not confuse it with the following where the comma is not acting as a sequence point:

somefunction(i++, ++i, j*i)


What about j = i++ * ++i

The multiplication operator is not a sequence point.


(Excuse me hijacking your answer)

From §3.4 of ISO 9899:1999 (C Standard):

3.4 behavior

external appearance or action

3.4.1 implementation-defined behavior

unspecified behavior where each implementation documents how the choice is made

EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit when a signed integer is shifted right.

3.4.2 locale-specific behavior

behavior that depends on local conventions of nationality, culture, and language that each implementation documents

EXAMPLE An example of locale-specific behavior is whether the islower function returns true for characters other than the 26 lowercase Latin letters.

3.4.3 undefined behavior

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

NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).

EXAMPLE An example of undefined behavior is the behavior on integer overflow.

3.4.4 unspecified behavior

behavior where this International Standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance

EXAMPLE An example of unspecified behavior is the order in which the arguments to a function are evaluated.

这篇关于是具有任何序列点问题,这个计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆