On 1/24/07, malaram kumhar <[EMAIL PROTECTED]> wrote:
> > You are invoking undefined behavior:
> >
> > http://c-faq.com/expr/evalorder2.html
> Since precedence if ++ is more than + so compiler first calculate all
> the incrementing values means
> for ++a it set the value of a=a+1=1+1=2(prefix increment)
> but in case of a++(postfix increment) first it put the value of a in
> expression,since the value of a=2 so it use a=2 for all a++.
> hencenow expression becomes:
> b=a+a+a+a=2+2+2+2=8(The increment in case of a++ will effect after ;)
Read again the link I provided, especially this line:
'It is not guaranteed that an increment or decrement is performed
immediately after giving up the previous value and before any other
part of the expression is evaluated. It is merely guaranteed that the
update will be performed sometime before the expression is considered
``finished'' '
That is why this is considered undefined -- it can provide ambiguous
side effects. Why would anyone be writing code like that to begin
with? You'd never use something like that in production code.
-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi