最终未定义的行为 [英] Eventual undefined behaviour

查看:69
本文介绍了最终未定义的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>


int main(void){

int i;


for(i = 1; i!= 0; i ++);

printf(" Finished!\ n");

返回0;

}


假设编译器足够聪明,可以意识到上面的

最终会溢出i。它可以拒绝在此基础上生成一个

可执行文件吗?

#include <stdio.h>

int main(void) {
int i ;

for (i=1 ; i != 0 ; i++) ;
printf("Finished !\n") ;
return 0 ;
}

Assume that a compiler is clever enough to realise that the
above will eventually overflow i. Can it refuse to produce an
executable on that basis ?

推荐答案

假设编译器很聪明足以意识到上面的
Assume that a compiler is clever enough to realise that the

最终会溢出i。是否可以拒绝在此基础上生成

可执行文件?
above will eventually overflow i. Can it refuse to produce an
executable on that basis ?



它不会。最终我会在达到它之后成为-ve最大值

然后它将变为0.所以它将终止。

华友世纪!

It won''t. Eventually i will become -ve after reaching it +ve maximum
and then it will become 0. So it will terminate.
Hurray!


文章< 11 ********************** @ 19g2000hsx.googlegroups。 com>,

Ravi< ra ********* @ gmail.comwrote:
In article <11**********************@19g2000hsx.googlegroups. com>,
Ravi <ra*********@gmail.comwrote:

>赢了T。最终我会在达到它之后成为-ve最大
然后它将变为0.所以它将终止。
>It won''t. Eventually i will become -ve after reaching it +ve maximum
and then it will become 0. So it will terminate.



在大多数机器上,但不保证。


- Richard

-

应考虑在一些字母表中需要多达32个字符

- X3.4,1963。

On most machines, but it''s not guaranteed.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


On Fri,2007年9月14日07:34:05 -0700,Spiros Bousbouras写道:
On Fri, 14 Sep 2007 07:34:05 -0700, Spiros Bousbouras wrote:

#include< stdio.h>


int main(无效){

int i;

for(i = 1; i!= 0; i ++);

printf(" Finished!\ n");

返回0;

}


假设一个编译器足够聪明,意识到上面的内容最终会溢出i。它可以拒绝在

的基础上生成可执行文件吗?
#include <stdio.h>

int main(void) {
int i ;

for (i=1 ; i != 0 ; i++) ;
printf("Finished !\n") ;
return 0 ;
}

Assume that a compiler is clever enough to realise that the above will
eventually overflow i. Can it refuse to produce an executable on that
basis ?



是的,但仅仅因为可以证明循环将始终执行。

如果函数的名称不同,那么编译器再也不能
证明它会被无条件调用,然后编译器必须接受代码。

Yes, but only because it can be proven that the loop will always execute.
If the function were named differently, and the compiler could no longer
prove it would be called unconditionally, then the compiler would have to
accept the code.


这篇关于最终未定义的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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