Integer "Overflow" Is Not Trapped without /D Debug Switch (11697)



The information in this article applies to:

  • Microsoft QuickBASIC 4.5
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q11697

SUMMARY

The following program returns the error "Overflow in line 20 of module at address xxxx:xxxx" when compiled with the /D switch:
   10  x% = 129
   20  print 256 * x%
   30  end
				
If the sample program is compiled without the /D switch, no error is reported, but an incorrect (negative) value is returned.

Forcing "256" to single precision by using 256! or 256.0 will eliminate the overflow error. "256" is an integer, and the result of 129 times 256 is greater than 32,767, which is the highest integer allowed.

This information applies to Microsoft QuickBasic Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS and to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2.

These compilers don't handle type coercion, nor do they check for overflow unless the program was compiled with the /D switch.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB11697