On Wed, May 27, 2009 at 4:09 PM, Arvind Balodia <[email protected]> wrote: > but tell why the compiler is giving me the results 12 and 12 to me for both > the expression and 11 and 12 as in the original problem.There must be a > strategy that each compiler must follow. I think you are right but you have > not given the complete answer.
That answer is that what you're doing is specifically mentioned in the C and C++ Standards as being _undefined_. This is a specific term to mean that the compiler writers may do anything in that situation (including what you consider to be the right answer consistently, what you consider to be a wrong answer, a different answer every time, or crash.) As such, any answer is 'correct.' Analysing /why/ you get a particular answer is futile, since the same compiler (or binary) may 'give the other answer' unexpectedly, and may also certainly be different when compiling under a different compiler. As such, you should not rely on such concepts and re-write the code in such a way that it /is/ valid C or C++: v = m++; v += ++m; -- PJH http://shabbleland.myminicity.com/com http://www.chavgangs.com/register.php?referer=9375
