本文介绍了C#:功能评测(VS C)顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看下面的C code( K&安培; R第77页的):

Take the following C code (K&R pg. 77) :

push(pop() - pop()); /* WRONG */

这本书说,自从 - / 是不可交换的运营商来说,要想在其中2 弹出函数求是必要的(显然,要获得正确的结果)......,因此你必须把第一函数的结果在一个变量,然后再与继续算术,像这样的:

The book says that since - and / are not commutative operators, the order in which the 2 pop functions are evaluated is necessary (obviously, to get the correct result)...and thus you have to put the result of the first function in a variable first and then proceed with the arithmetic, like such:

op2 = pop();
push(op2 - pop());

显然,这是因为编译器不能保证在命令函数求(为什么?)

Apparently this is because the compiler can't guarantee in which order the functions are evaluated (...why?)


我的问题是,C#这样做同样的事情?如,我担心这样的事情用C#时?并对于这个问题,任何其他高级语言

My question is, does C# do this same thing? as in, do I have to worry about this sort of thing when working with C# ? and for that matter, any of the other higher level languages ?

推荐答案

在C#是从左到右依次为:http://blogs.msdn.com/oldnewthing/archive/2007/08/14/4374222.aspx

In C# it is left to right: http://blogs.msdn.com/oldnewthing/archive/2007/08/14/4374222.aspx


回复:C ++为了

显然,这是因为编译器不能保证在命令函数求(为什么?)

任何特定的编译器可以保证顺序。问题是,语言规范没有指定的顺序,所以每个编译器可以为所欲为。这意味着你有两个方法调用之间增加一个序列点,如果你想保证订货。

Any particular compiler can guarantee the order. The problem is that the language spec does not specify an order, so each compiler can do whatever it wants. This means you have to add a sequence point between the two method calls if you want to guarantee ordering.

这篇关于C#:功能评测(VS C)顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 20:01