Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Is something wrong with the compiler ? Message-ID: <1990Sep28.151723.24287@zoo.toronto.edu> Organization: U of Toronto Zoology References: <884@gtenmc.UUCP> <1990Sep26.175948.8232@zoo.toronto.edu> Date: Fri, 28 Sep 90 15:17:23 GMT In article burley@world.std.com (James C Burley) writes: > Sure you know what the results should be? The second expression is > assigning to `a' twice, which has unpredictable effects... > >Hmm, I thought it was ok -- doesn't "=" serve as a "sequence point" or >some such thing, and since the lhs of the outer = is so simple it can't >be "evaluated" before the rhs has been, and the rhs contains the other >=, one is guaranteed the latter = is performed before the former, right? Wrong. Assignment is not a sequence point. Furthermore, taking the value of an assignment is no guarantee that the assignment has been performed. It's quite legal for the compiler to save up all the assignments and do them at the end of the expression, if that happens to be more convenient. The only constraint is that the update to the lhs must occur somewhere between the previous and the next sequence point. In the absence of intervening sequence points (*some* operators do cause them), the result of modifying an object's value more than once in the same expression is specifically undefined. It might work. It might fail. It might work only when the Moon is full. It might use your modem to place a call to the Pentagon and request an airstrike on your house. :-) -- Imagine life with OS/360 the standard | Henry Spencer at U of Toronto Zoology operating system. Now think about X. | henry@zoo.toronto.edu utzoo!henry