Microsoft KB Archive/40413

From BetaArchive Wiki
Knowledge Base


Recursive FUNCTION Procedure Shouldn't Be STATIC in QuickBasic

Article ID: 40413

Article Last Modified on 11/21/2006

This article was previously published under Q40413

SUMMARY

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%)
                

MORE INFORMATION

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.


Additional query words: QuickBas BasicCom

Keywords: KB40413