unbelievable "simple" question/bug?

Christopher R Volpe volpe at camelback.crd.ge.com
Fri Mar 29 02:56:24 AEST 1991


In article <8331 at umd5.umd.edu>, jjk at jupiter.astro.umd.edu (Jim
Klavetter) writes:
|>It isn't precedence or some side effect, it is just weird.  I have the
|>code fragment (a, b, c, integers)
|>
|>	if(a-b-c>0)
|>		do ifstuff
|>	else
|>		do elsestuff
|>
|>When a=b=c=1 the above should translate to if(-1>0) and the elsestuff
|>should get done.  It doesn't.  I tried putting parens around (a-b-c)
|>(which should be unnecessaray) and it didn't make any difference.  OK,
|>now here is the real weird part:  if I have the following:
|>	temp=a-b-c;
|>	if(temp>0)
|>		do ifstuff
|>	else
|>		do elsestuff
|>it works as expected!  Anybody want to tell me what I'm missing?

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
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list