Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!yale!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.c Subject: int divided by unsigned. Message-ID: <13940@lanl.gov> Date: 15 Jun 89 23:47:31 GMT Distribution: na Organization: Los Alamos National Laboratory Lines: 23 #include "stdio.h" main(){ int a; unsigned b; a= -5; b=1000; printf("%d\n",a/=b); } I tried the above program on my sun workstation and it printed 4294967. This is aparently the "correct" answer according to the proposed C standard. On the Cray under UNICOS, the same program prints 0. The "correct" answer for the Cray would have been 18446744073709551. This is an example of a case where deviating from the C definition produces desireable results. I hope Cray doesn't "fix" their C compiler. (Note: this behaviour occurs because C requires arguments to be "promoted" to unsigned if either is already unsigned. The preferable rule would be that if one argument is an int and the other is an unsigned, _both_ should be promoted to long before the operator is applied. Unsigned is _not_ a promotion from int - it is a break-even semantics change.)