unbelievable "simple" question/bug?

Jim Klavetter jjk at jupiter.astro.umd.edu
Thu Mar 28 16:06:47 AEST 1991


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?

Obviously, this really isn't the exact code, so I'll give a few more
details which I don't think are relevant.  I'm using gcc on a sun4
running sunos 4.1.  "a" is really argc and "b" is really optind but I
know that isn't relevant because I check their values (as well as "c")
both before the if and in both branches and all three values don't
change (as expected).

Thanks for any help possible with this one.

jjk at astro.umd.edu also for Athabasca and Reudi
Jim Klavetter
Astronomy
UMD
College Park, MD  20742



More information about the Comp.lang.c mailing list