KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q28154: A RETURN Without a GOSUB in a Subprogram Hangs in EXE

Article: Q28154
Product(s): See article
Version(s): 6.00    | 6.00
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | | mspl13_basic
Last Modified: 11-JUL-1990

Executing a RETURN statement without a corresponding GOSUB in a
subprogram hangs an EXE program when compiled without the BC /D
option. You must compile with the BC /D option (or compile in the
QuickBASIC environment) to trap a "RETURN without GOSUB" programming
error (just as you must use BC /D to trap array bounds violations).

This information applies to BC.EXE in Microsoft BASIC Compiler
versions 6.00 and 6.00b for MS-DOS and MS OS/2, to BC.EXE in Microsoft
BASIC Professional Development System (PDS) version 7.00 for MS-DOS
and MS OS/2, and to BC.EXE in QuickBASIC versions 4.00, 4.00b, and
4.50 for MS-DOS.

Compile the test program below with BC.EXE and then link it. If you
compile with the BC /D option, the program gives run-time error,
"RETURN without GOSUB." If you don't compile with /D, the program
hangs the computer at run time without telling you about your
programming mistake.

To avoid hanging due to a programming error like this, use the QB.EXE
or QBX.EXE environment as a debugger, since the interpreter
environment correctly traps the "Return without GOSUB" error. The
program should be modified to remove the "Return without GOSUB"
programming error.

Code Example
------------

' test.bas
   defint a-z
   declare sub atest ( x )

     i = 1
     print i
     call atest (i)
     print i
   end

   sub atest ( j )
      print j
      j = 2
      print j
      return
   end sub

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.