Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!usc!elroy!csun!fedeva!premise!mirror!frog!john From: john@frog.UUCP (John Woods) Newsgroups: comp.lang.c Subject: Re: int divided by unsigned. Message-ID: <1549@frog.UUCP> Date: 23 Jun 89 23:59:00 GMT References: <13940@lanl.gov> Distribution: na Organization: Misanthropes-R-Us Lines: 32 In article <13940@lanl.gov>, jlg@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@frog.UUCP, ...!mit-eddie!jfw, jfw@eddie.mit.edu People...How you gonna FIGURE 'em? Don't bother, S.L.--Just stand back and enjoy the EVOLUTIONARY PROCESS...