Bug fix for Turbo C ?

apm233m at vaxc.cc.monash.edu.au apm233m at vaxc.cc.monash.edu.au
Wed Jun 26 15:51:39 AEST 1991


My question is: is there a patch for Turbo C++ v1.0 to fix the following
code generation bug?

The bug concerns the code generated for a right shift of longs.

The following short program demonstrates the bug.

   main()
   {
   long bad=-2, good=-4;
   printf("Is this true?: -1=%ld, -1=%ld\n", bad >> 1, good >> 2);
   }

My copy of TC++ generates an .exe which produces:
   Is this true?: -1=2147483647, -1=-1

This bug occurs only for shifts of longs, and only if the shift is
by the constant "1". It is a bug in the generated code; the preprocessor
does not have the bug and therefore cannot be used to detect the bug.
The actual generated code is:
	shr	ax,1
	rcr	dx,1
whereas the correct code would be:
	sar	ax,1
	rcr	dx,1

-- 
---------------
Bill Metzenthen
Mathematics Department
Monash University
Australia



More information about the Comp.lang.c mailing list