QB/QBX "Out of Stack Space" Using Large TYPE as SUB Parameter (57711)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1

This article was previously published under Q57711

SYMPTOMS

The program below demonstrates a problem with the QuickBasic (QB.EXE) and QuickBasic Extended (QBX.EXE) editors in which the environment runs out of stack space when passing a large user-defined TYPE variable to a SUBprogram.

STATUS

Microsoft has confirmed this to be a bug in QB.EXE in Microsoft QuickBasic versions 4.00, 4.00b, and 4.50 for MS-DOS; in QB.EXE shipped with Microsoft Basic Compiler 6.00 and 6.00b (buglist6.00, buglist6.00b) for MS-DOS; and in the QBX.EXE editor that comes with Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS (buglist7.00, buglist7.10). We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This problem does not occur in .EXE programs compiled with BC.EXE.

MORE INFORMATION

The minimum code to duplicate this "Out of stack space" error is as follows:

  1. Create a TYPE that is near the size of, or larger than, the available stack space. (A TYPE with 2400 bytes is adequate to show the problem in both QB.EXE and QBX.EXE. QB.EXE has a default program stack size of 2K, and QBX.EXE has a default program stack size of 3K).
  2. DIMension an array of that TYPE. An array of one element is all that is necessary to reproduce the problem. The array can be either $DYNAMIC or $STATIC.
  3. Create a SUBprogram that takes a single element of this TYPE as a parameter. The SUB does not have to contain any code at all.
  4. CALL the SUB and pass one element of this array.
  5. Run the program by pressing SHIFT+F5 in the environment.
Attempting to run this program in the editor produces an "Out of stack space" error followed by an "Out of memory" error before the program even begins to execute. The errors do NOT occur at the time of the CALL because the program is pushing information onto the stack. This can be shown by putting a breakpoint on the CALL and then attempting to execute the program. The CALL is never reached; the problem occurs during the binding and final memory allocation steps.

This problem does not occur when the program is compiled with the BC.EXE compiler.

To work around this problem, dimension the TYPEd array with DIM SHARED or put it in a COMMON SHARED statement.

The following is the minimum amount of code needed to reproduce the problem:
   DECLARE SUB sub1 (boot AS ANY)
   TYPE rec1
     jump1 AS STRING * 2400
   END TYPE
   DIM var1(1) AS rec1
   CALL sub1(var1(1))
   END
   SUB sub1 (boot AS rec1)
   END SUB
				
The following code example shows one workaround:
   DECLARE SUB sub1 ()
   TYPE rec1
     jump1 AS STRING * 2400
   END TYPE
   DIM SHARED var1(1) AS rec1
   CALL sub1
   END
   SUB sub1
   END SUB
				

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