Find limit of recursion: Difference between revisions

Added XPL0 example.
m (→‎{{header|Zig}}: Note for 0.10.x versions)
(Added XPL0 example.)
Line 3,357:
536870500
Segmentation fault (core dumped)
</pre>
 
=={{header|XPL0}}==
On the Raspberry Pi this causes a Segmentation fault at the recursion
levels shown in Output.
 
The stack size is about 8 MB. The original compiler pushes a single
4-byte value (the return address for Recurse) onto the stack.
 
The optimizing compiler pushes an additional 4-byte value (r11), which is
the base address of variables local to Recurse. But since there aren't
any local variables in this situation, the optimizing compiler isn't as
optimal as it could be.
 
The MS-DOS version crashes at 12,224 levels. The allocated stack size is
16,384 bytes. But since each call pushes a 4-byte value, the actual limit
should be a maximum of 4,096.
 
<syntaxhighlight lang "XPL0">int Lev;
proc Recurse;
[if (Lev & $3FF) = 0 then
[IntOut(0, Lev); ChOut(0, ^ )];
Lev:= Lev+1;
Recurse;
];
 
[Lev:= 0;
Recurse;
]</syntaxhighlight>
{{out}}
<pre>
2,096,128 for the original compiler (xplr)
1,047,552 for the optimizing compiler (xpl0)
</pre>
 
290

edits