On 18 Apr 2007 06:08:40 -0700, Jim Dougherty <[EMAIL PROTECTED]> wrote: > > > > [email protected] wrote: > > On 17 Apr 2007 13:13:15 -0700, Mohammad Nabil <[ > > mailto:mohamad80986%40yahoo.com [EMAIL PROTECTED]> wrote: > >> I think that's not undefined behavior the compiler translates as > follows: > > > > You're wrong. > > > > Any code of the form: > > > > i = ++i; > > > > or > > > > x = y + y++; > > > > where a variable is modified more than once in 'a statement' (formally > > 'between sequence points') produces undefined behaviour. Just because . > . . > > I am not sure that I understand, did you give a bad example? I do not see > that > any variable is modified more than once in "x = y + y++". It looks to me > like x > is modified once and y is modified once. Are you saying that the behavior > of > this statement is undefined?
I am, however I omitted 'and/or examined' in my sentence. x = y + y++; is indeed undefined. Assume int x, y=1; x = y + y++; which *happens* first? Does 'y' get evaluated then 'y++' ? Or 'y++' then 'y'? The Standard explicitly doesn't say. It may specify how the evaluated values are subsequently used (left to right/right to left depending on operator) but places no restraints on the actual order of individual evaluation before applying precedence. To clarify my original statement, you cannot both modify and examine a variable within a sequence point, nor modify a variable more than once within a sequence point. -- PJH Aio, quantitas magna frumentorum est [Non-text portions of this message have been removed]
