--- In [email protected], Mohammad Nabil <[EMAIL PROTECTED]> wrote:
>
> I think that's not undefined behavior
> the compiler translates as follows:
> 
> the first operation:
> the compiler "sees" 2 "++" prefixes and so it translates
> them making x = 11 so the answer is 33
> the second operation is exactly like the first one
> and since no space between the two outputs then 3333
> is written to the screen.
> 
> the third operation:
> the comiler sees one ++ postfix so it translates it but
> after the "cout" so the output is 333327
> 
> the fourth operation is exactly like the third but for
> one difference; the "cout" is translated after the
> translation of the computations so the incrementation
> in x is executed from 27 to 28. 
> 
> so the final output is 33332728.
<snip>

No question, you obviously have understood right how one particular
compiler interprets the C code.
Nonetheless changing one and the same variable more than once between
two sequence points DOES provoke undefined behaviour. So I feel
obliged to repeat myself here:

If you don't know exactly what the term "undefined behaviour" means,
google for "Nasal Demon" or ask Wikipedia for this term, then follow
the link named "Undefined Behaviour".

And if anyone still doesn't trust me that constructions like
  ++x + x++
provoke undefined behaviour, then please get a copy of the ANSI C
standard (look up the Files section of this Yahoo! board for the
latest drafts) and look up what "undefined behaviour" is defined like.

End of discussion, I suggest; there's no use in discussing
well-defined terms here. In most cases where such discussions have
started over the past two years they have only had one effect: namely
exaggerating into a flame war. And this is as useless as can be.

Regards,
Nico

Reply via email to