int divided by unsigned.

John Woods john at frog.UUCP
Sat Jun 24 09:59:00 AEST 1989


In article <13940 at lanl.gov>, jlg at lanl.gov (Jim Giles) writes:
O> #include "stdio.h"
u> main(){
r>    int a = -5;			/* editted for rebroadcast */
 >    unsigned b = 1000;
C>    printf("%d\n",a/=b);
 > }
"> I tried the above program on my sun workstation and it printed 4294967.
e> This is aparently the "correct" answer according to the proposed C
x> standard.  On the Cray under UNICOS, the same program prints 0.  The
p> "correct" answer for the Cray would have been 18446744073709551.  This
e> is an example of a case where deviating from the C definition produces
r> desireable results.  I hope Cray doesn't "fix" their C compiler.
t> 
">

Try

	main() {
		int a = -5;
		unsigned b = 1000;

		printf("%d\n", a /= (int)b);
	}

A correct program giving desirable results.  Fancy that.

-- 
John Woods, Charles River Data Systems, Framingham MA, (508) 626-1101
...!decvax!frog!john, john at frog.UUCP, ...!mit-eddie!jfw, jfw at eddie.mit.edu
    People...How you gonna FIGURE 'em?
    Don't bother, S.L.--Just stand back and enjoy the EVOLUTIONARY PROCESS...



More information about the Comp.lang.c mailing list