Is something wrong with the compiler ?
James C Burley
burley at world.std.com
Thu Sep 27 15:33:12 AEST 1990
In article <1990Sep26.175948.8232 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
In article <884 at gtenmc.UUCP> csp at 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 at world.std.com
More information about the Comp.lang.c
mailing list