KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q40413: Recursive FUNCTION Procedure Shouldn’t Be STATIC in QuickBASIC

Article: Q40413
Product(s): See article
Version(s): 4.00 4.00b 4.50
Operating System(s): MS-DOS
Keyword(s): ENDUSER | docerr SR# S890111-178 B_BasicCom | mspl13_basic
Last Modified: 8-DEC-1989

Further below is a correction that applies to the factorial example
program (in the Recursive Procedures section) in the following
manuals:

1. Page 82 of "Microsoft QuickBASIC 4.0: Programming in BASIC:
   Selected Topics" (for QuickBASIC 4.00 and 4.00b)

2. Page 82 of "Microsoft BASIC Compiler 6.0 for MS OS/2 and MS-DOS:
   Programming in BASIC: Selected Topics" (for 6.00 and 6.00b)

3. Page 72 of "Microsoft QuickBASIC 4.50: Programming in BASIC"

4. Page 68 of "Microsoft BASIC Version 7.0: Programmer's Guide"

In the factorial function, the STATIC clause should be removed from
the FUNCTION line so that it reads as follows:

   FUNCTION Factorial# (N%)

The example on this page incorrectly defines the recursive function to
be STATIC when it should actually be non-STATIC. Recursive functions
should be defined as non-STATIC because the usefulness of a recursive
function relies on automatic variables saved temporarily on the stack,
instead of variables that retain their values between invocations.

The function Factorial# depends on the value for N% to be correct in
each level of the recursive iteration. The value for N% cannot be
correct if the number is not stored on the stack with each recursive
call.

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.