Microsoft KB Archive/40413
Article ID: 40413
Article Last Modified on 11/21/2006
This article was previously published under Q40413
Further below is a correction that applies to the factorial example program (in the Recursive Procedures section) in the following manuals:
- Page 82 of "Microsoft QuickBasic 4.0: Programming in Basic: Selected Topics" (for QuickBasic 4.00 and 4.00b)
- 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)
- Page 72 of "Microsoft QuickBasic 4.50: Programming in Basic"
- 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.
Additional query words: QuickBas BasicCom