30 GOTO 10总是会转到10吗? [英] Will 30 GOTO 10 always go to 10?

查看:157
本文介绍了30 GOTO 10总是会转到10吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本着最新播客的精神,乔尔提到他想与可能有趣的答案...



在当今我们必须编程的环境中,我们不能依赖于我们的语言语句的执行顺序。真的吗?我们应该担心吗?



30 GOTO 10总是会转到10吗?*



*我没有故意使用20;)



投票赞成结束这个问题的四个人...



<运行时编译器使用分析信息来帮助优化正在编译的代码。JVM被允许使用特定于执行的信息以产生更好的代码,这意味着一个程序中的编译方法M可能生成与编译不同的代码。 M在另一个



(来自Java并发实践,2006年,Goetz等人)



。看看单态调用转换



[edit]



和另一次修改,您的处理器可以交换语句的执行顺序...

解决方案

不,不会。但是它总是像它那样表现。编译器设计中的基本规则之一是好像规则。只要结果符合您的语言规则,您的编译器就可以进行所需的任何更改,只要它们遵循语言规则即可。



只要编译器可以保证不会改变程序的结果,GOTO 10可能会决定跳到其他位置。



因此,不应该不用担心。


In the spirit of the latest podcast where Joel mentioned he'd like some simple questions with possibly interesting answers ...

In the environments we have to programme in today we can't rely on the order of execution of our langauage statements. Is that true? Should we be concerned?

Will 30 GOTO 10 always go to 10?*

*I didn't use 20 on purpose ;)

[edit] for the four people voting for closure of this question ...

"Runtime compilers use profiling information to help optimize the code being compiled. The JVM is permitted to use information specific to the execution in order to produce better code, which means that the compiling method M in one program may generate different code than compiling M in another"

(from Java concurrency in practice, 2006, Goetz et al)

.. have a look at "monomorphic call transformation"

[edit]

and another edit, your processor is allowed to swap the order of execution of statements ...

解决方案

No, it will not. But it will always behave as if it did. One of the basic rules in compiler design is the "as if" rule. Your compiler can make whatever changes it likes, as long as the result is going to behave as if you'd followed the language rules.

GOTO 10 may decide to jump to some other location, as long as the compiler can guarantee that it won't change the outcome of the program.

So no, it shouldn't worry you.

这篇关于30 GOTO 10总是会转到10吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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