Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!njin!princeton!udel!wuarchive!uwm.edu!bionet!agate!ucbvax!unisoft!greywolf From: greywolf@unisoft.UUCP (The Grey Wolf) Newsgroups: comp.lang.c Subject: Re: A define problem Keywords: define Message-ID: <3302@unisoft.UUCP> Date: 16 Jan 91 20:31:46 GMT References: <440@bally.Bally.COM> <1991Jan8.012923.3390@oswego.Oswego.EDU> <4613@sactoh0.SAC.CA.US> Reply-To: greywolf@unisoft.UUCP (The Grey Wolf) Distribution: usa Organization: Foo Bar and Grill Lines: 49 In article <4613@sactoh0.SAC.CA.US> jak@sactoh0.SAC.CA.US (Jay A. Konigsberg) writes: >In article <1991Jan8.012923.3390@oswego.Oswego.EDU> hunter@oswego.Oswego.EDU (Eric Hunter) writes: >>In article <440@bally.Bally.COM> siva@bally.Bally.COM (Siva Chelliah) writes: >> >>>#define half(x) (x)/2 >>>main () >>>{ >>> int i=5; >>> printf( "i/2 = %d\n",half(i-5)); >>>} >>>This program prints 3 instead of 0 ! How can I make it print 0 ? >> >>You could get a new compiler. ;^} >> > >Bzzzt. Wrong, but thank you for playing :-) Bzzzzt. Wrong, but thank you for replying :-) > >Look at what is being passed to "half()". Nothing's wrong with it... > >i=5 >half(i-5) or half(5-5) or half(0) > >which becomes: (0)/2 - which is 0. Exactly the problem. Siva WANTS that to happen, but is getting 3 instead! > >It looks like it should be: > >printf( "i/2 = %d\n",half(i)); > >which produces 2, not 3 anyway. If you want to round up, you should >define the variables as a float, add .5 and cast to (int). You are attempting to rewrite someone else's logic after they explicitly state what they want. It seems to be general consensus that Siva's C compiler is broken. -- On the 'Net: Why are more and more fourth-level wizard(-wannabe)s trying to invoke ninth-level magic, instead of taking the time to climb the other (quite essential) thirteen levels so they can do this properly? ...!{ucbvax,acad,uunet,amdahl,pyramid}!unisoft!greywolf