Is something wrong with the compiler ?

Kevin D. Quitt kdq at demott.COM
Wed Oct 3 07:42:05 AEST 1990


In article <1895 at tuvie> hp at vmars.tuwien.ac.at (Peter Holzer) writes:
>
>Expression:					Value:
>(a = ~0)					(int) ~0
>(unsigned)(a = ~0)				(unsigned) ~0
>((unsigned)(a = ~0) >> 1)			(unsigned) MAXINT
>(int)((unsigned)(a = ~0) >> 1)			(int) MAXINT
>a = (int)((unsigned)(a = ~0) >> 1)		(int) MAXINT
>
>Anything wrong with my reasoning?

    Yes.  Undefined order or assignment means undefined.  It is
perfectly legitimate for the (a = ~0) assignment to actually take place
after the a = (int)((unsigned)(a = ~0) >> 1) assignment.  That's what
undefined order means. 

    I agree that a proper compiler "knows" that the former is
unnecessary, and can/will be optimized away, but a compiler that isn't
that smart *isn't* broken (according to the spec).

-- 
 _
Kevin D. Quitt         demott!kdq   kdq at demott.com
DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last

                96.37% of all statistics are made up.



More information about the Comp.lang.c mailing list