Path: utzoo!attcan!uunet!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.c Subject: Re: Is something wrong with the compiler ? Message-ID: Date: 27 Sep 90 05:33:12 GMT References: <884@gtenmc.UUCP> <1990Sep26.175948.8232@zoo.toronto.edu> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 23 In-Reply-To: henry@zoo.toronto.edu's message of 26 Sep 90 17:59:48 GMT In article <1990Sep26.175948.8232@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: In article <884@gtenmc.UUCP> csp@gtenmc.UUCP (Charudutta S Palkar) writes: > ... I wrote the following code , and the results I got were absurd. > > printf(" Maxint : %d\na = %d\n", ( int )(( unsigned ) ~0 >> 1 ) , > a = ( int )(( unsigned ) ( a = ~0 ) >> 1 )); Sure you know what the results should be? The second expression is assigning to `a' twice, which has unpredictable effects. However, this doesn't explain what you're seeing. It does look to me like a compiler bug. 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? On the other hand, "b = a + (int)((unsigned)(a=~0)>>1));" would be undefined as to whether the first mention of "a" identifies the value it holds prior to execution of the statement or the value ~0. James Craig Burley, Software Craftsperson burley@world.std.com