A define problem

The Grey Wolf greywolf at unisoft.UUCP
Thu Jan 17 07:31:46 AEST 1991


In article <4613 at sactoh0.SAC.CA.US> jak at sactoh0.SAC.CA.US (Jay A. Konigsberg) writes:
>In article <1991Jan8.012923.3390 at oswego.Oswego.EDU> hunter at oswego.Oswego.EDU (Eric Hunter) writes:
>>In article <440 at bally.Bally.COM> siva at 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



More information about the Comp.lang.c mailing list