gpt4 book ai didi

c - 这个程序有任何序列点问题吗?

转载 作者:太空宇宙 更新时间:2023-11-04 00:13:58 25 4
gpt4 key购买 nike

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

j=(i++,++i,j*i);这个定义好吗?让我澄清一下我的疑问。

最佳答案

这个表达式是可以的,因为 comma operatorsequence point :

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

但是不要将它与以下逗号不作为序列点的地方混淆:

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

What about j = i++ * ++i

乘法运算符不是序列点。


(不好意思盗用你的答案)

来自 ISO 9899:1999(C 标准)的 §3.4:

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.

关于c - 这个程序有任何序列点问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3590170/

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