Jump to content

Find limit of recursion: Difference between revisions

COBOL
(Adding MUMPS example)
(COBOL)
Line 125:
 
Segmentation fault occurs when i is 523756. (This was checked debugging with gdb rather than waiting the output: the printf line for the test was commented). It must be noted that the recursion limit depends on how many parameters are passed onto the stack. E.g. adding a fake double argument to <code>recurse</code>, the limit is reached at <code>i == 261803</code>. The limit depends on the stack size and usage in the function. Even if there are no arguments, the return address for a call to a subroutine is stored on the stack (at least on x86 and many more processors), so this is consumed even if we put arguments into registers.
 
=={{header|COBOL}}==
{{works with|OpenCOBOL 1.1}}
<lang cobol> identification division.
program-id. mung.
data division.
working-storage section.
01 depth-counter pic 9(3).
procedure division.
100-main.
move 0 to depth-counter.
display "Mung until no good.".
perform 200-mung.
display "No good.".
stop run.
200-mung.
add 1 to depth-counter.
display depth-counter.
perform 200-mung.</lang>
Compiled with <pre>cobc -x -g mung.cbl</pre> gives, after a while,
<pre>...
249
250
251
252
253
mung.cbl:17: libcob: Stack overflow, possible PERFORM depth exceeded</pre>
 
Without stack-checking turned on (achieved with -g in this case), it gives
<pre>...
249
250
251
252
253
254
Attempt to reference unallocated memory (Signal SIGSEGV)
Abnormal termination - File contents may be incorrect</pre>
 
=={{header|C sharp|C#}}==
Line 145 ⟶ 184:
 
Through execution (with Mono), another user has reached 697186.
 
=={{header|D}}==
<lang d>import std.c.stdio: printf;
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.