Previous | Next | Table of Contents | Index | Program List | Copyright

13.7 Tricks of the Trade: Debugging Recursive Subprograms

The most common problem with a recursive procedure or function is that it may not terminate properly. For example, if the terminating condition is not correct or incomplete, the procedure may call itself indefinitely or until all available memory is used up. Normally, a "stack overflow," or Storage_Error exception, is an indicator that a recursive procedure is not terminating. Make sure that you identify all stopping cases and provide a terminating condition for each one. Also be sure that each recursive step leads to a situation that is closer to a stopping case and that repeated recursive calls will eventually lead to stopping cases only.

Sometimes it is difficult to observe the result of a recursive procedure execution. If each recursive call generates a large number of output lines and there are many recursive calls, the output will scroll down the screen more quickly than it can be read. On most systems it is possible to stop the screen temporarily by pressing a control character sequence (e.g., Control-S). If this cannot be done, it is still possible to cause your output to stop temporarily by displaying a prompting message followed by a Ada.Text_IO.Get(NextChar)operation. Your program will resume execution when you enter a data character.


Previous | Next | Table of Contents | Index | Program List | Copyright

Copyright © 1996 by Addison-Wesley Publishing Company, Inc.