On Wed, May 27, 2009 at 3:19 PM, Arvind Balodia
<[email protected]> wrote:

> (m++)+(++m)

> it means first take m and after the execution increase its value by 1 and add 
> m
> again but before the execution increase its value by 1

But which of (m++) and (++m) is executed first? It's up to the
compiler to decide (since you've decided to use an expression that
isn't allowed,) and it may change its mind between compiles since it
doesn't have to do them in any particular order. To rephrase, while
there may be a left-to-right/right-to-left usage of things like + and
/, the order the expressions themselves either side of that symbol are
evaluated in is not dictated by any of the standards.

To simplify the explanation, for example in the following sequence:

int a=2, b=3, c=0;
c = (a++)+(++b);

The compiler is free to evaluate ++b before evaluating a++. Or it can
evaluate a++ before ++b.

Either way, the result is the same. And well defined.

However if you replace a and b with the same variable (which, to
repeat, is NOT ALLOWED in C or C++) any result you get from this
expression is indeterminate depending on which one the compiler does
first.

Any further attempted justification of the original expression is
futile, because each compiler is free to return whatever it likes for
such an expression, including one that cannot be 'justified.'


-- 
PJH

http://shabbleland.myminicity.com/com
http://www.chavgangs.com/register.php?referer=9375

Reply via email to