Find limit of recursion: Difference between revisions
Content added Content deleted
(→{{header|VBScript}}: ++ x86 asm) |
(→{{header|C sharp|C#}}: Added C#) |
||
Line 82: | Line 82: | ||
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. |
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|C sharp|C#}}== |
|||
<lang csharp> |
|||
static void Main(string[] args) |
|||
{ |
|||
Recur(0); |
|||
Console.Read(); |
|||
} |
|||
private static void Recur(int i) |
|||
{ |
|||
Console.WriteLine(i); |
|||
Recur(i + 1); |
|||
}</lang> |
|||
Through debugging, the highest I achieve is 14250. |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
<lang fortran>program recursion_depth |
<lang fortran>program recursion_depth |