Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!sdd.hp.com!spool.mu.edu!news.nd.edu!mentor.cc.purdue.edu!purdue!haven!umd5!jupiter.astro.umd.edu!jjk From: jjk@jupiter.astro.umd.edu (Jim Klavetter) Newsgroups: comp.lang.c Subject: followup to Re: unbelievable "simple" question/bug? Summary: why do I need a cast? Message-ID: <8333@umd5.umd.edu> Date: 28 Mar 91 23:19:24 GMT References: <8331@umd5.umd.edu> <17989@crdgw1.crd.ge.com> Sender: news@umd5.umd.edu Reply-To: jjk@astro.umd.edu (Jim Klavetter) Distribution: na Organization: U of Md., Astronomy Program Lines: 26 > >Are you sure they are all ints? If one of either a or b or c is really >an UNSIGNED int, then a-b-c would be some big positive number, which >would explain the first example. If temp is an int, then putting that >big positive integer back in temp would do what you want, since temp >would then have the value -1. >================== >Chris Volpe Thanks to Chris and the others who e-mailed me, this was indeed the case. I took the original expression and added a cast to make all types "int" and it worked as expected. According to PROGRAMMING IN ANSI C by Kochan, there are 6 rules for data type conversions. Unfortunately, nowhere in those rules does the question of int vs unsigned (int) enter. Upon reflection, I think this is a mistake, or at least shortcoming, of this text. Does K&R2 explicitely mention this? Also, can someone post or send the full set of conversion rules? I would like to know exactly what I was comparing. Thanks again. jjk@astro.umd.edu also for Athabasca and Reudi Jim Klavetter Astronomy UMD College Park, MD 20742