DEFINITE bug in Turbo C 2.0

Hendrik Vermooten hendrik at zeusa.UUCP
Thu Mar 22 17:21:31 AEST 1990


Here is a definite bug in C (discovered by Renier v. Wyk)

(Please, no speeches about not using ++a etc in a macro :-) I've never
 done it, and never plan to do it. Interesting bug, nonetheless)

#include <stdio.h>
#define SQR(a) a*a
main ()
{
	int a = 10, b = 10, x, y;

	x = SQR (++a);
	y = SQR (b++);
	printf ("%d\n", x);
	printf ("%d\n", y);
	a = 10;
	b = 10;
	printf ("%d\n", SQR (++a));
	printf ("%d\n", SQR (b++));
}

Run by Turbo C it gives:

144
100
132
110

And run by Microsoft C (under XENIX):

132
110
132
110

 *** ***     Hendrik Vermooten, ZEUS software
 * o o *     Bang: ..!uunet!ddsw1!olsa99!zeusa!hendrik
O|  I  |O    or hendrik at zeusa.UUCP
 | *** |
 \*****/



More information about the Comp.lang.c mailing list