Turbo C bug !

Tommy Levitte pk-tle at sics.se
Sat Jan 21 19:32:47 AEST 1989


Hrmm...

I think I found a bug in Turbo C 2.0 . The funny thing is it didn't exist in
earlier versions!

This tiny program shows it

---

#define X 240
#define Y 240
#define Z ((X)*(Y))

void fn(unsigned long i)
{
 printf("%ld %ul\n",i,i)
}

main()
{
 fn(Z);
}

-----

Running this gave me a nice surprise:
-7936 2147475712

But if I change fn(Z) with fn(57600), it gives me the right numbers:
57600 57600

(57600 = 240*240   !!!!!!!)

This gave me problems when I gave exactly that kind of define to malloc() !!!

Fix : Put an L at the end of 240 !!!!

--
Tommy Levitte 
	pk-tle at draken.nada.kth.se
	pk-tle at sics.sics.se
	gizmo at kicki.stacken.kth.se



More information about the Comp.lang.c mailing list