C#: Order of function evaluation (vs C)

后端 未结 8 591
旧时难觅i
旧时难觅i 2020-12-19 07:08

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

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

The book says that since - and /

8条回答
  •  天涯浪人
    2020-12-19 07:49

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


    Re: C++ order

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

    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.

提交回复
热议问题