xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/run.c (revision e5cb852c65c532c79a7d83e6e6c8663886e00327)
1 /*
2  *	This simple classical example of recursion is useful for
3  *	testing stack backtraces and such.
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "../lib/unbuffer_output.c"
10 
11 int factorial (int);
12 
13 int
main(int argc,char ** argv,char ** envp)14 main (int argc, char **argv, char **envp)
15 {
16   gdb_unbuffer_output ();
17 
18 #ifdef FAKEARGV
19     printf ("%d\n", factorial (1)); /* commands.exp: hw local_var out of scope */
20 #else
21     if (argc != 2) {
22 	printf ("usage:  factorial <number>\n");
23 	return 1;
24     } else {
25 	printf ("%d\n", factorial (atoi (argv[1])));
26     }
27 #endif
28     return 0;
29 }
30 
factorial(int value)31 int factorial (int value)
32 {
33     int  local_var;
34 
35     if (value > 1) {
36 	value *= factorial (value - 1);
37     }
38     local_var = value;
39     return (value);
40 } /* commands.exp: local_var out of scope  */
41