I am getting a recursion problem I don't understand. (gpc-20040516, LINUX on a Pentium 4 laptop.)
This is a (silly) example program (enclosed as a gzipped tar file.):
program subset_problem(input,output); const setlimit = 4; type subset = set of 0..255;
var seta, setb: subset;
function recursive_setprint(set1: subset):subset; var i : integer; found : boolean; returned : boolean;
begin if set1 <> [] then begin i:= 0; found := false; while ((i <= setlimit) and (not found)) do begin if i in set1 then begin writeln('first element: ',i); found := true; recursive_setprint := recursive_setprint(set1 - [i]); end; i := i + 1; end end end;
begin seta := [0..setlimit]; setb := recursive_setprint(seta); end.
I'm getting the following output: first element: 0 first element: 1 first element: 2 first element: 3 first element: 4 first element: 4 first element: 3 first element: 4 first element: 4 first element: 2 first element: 3 first element: 4 first element: 4 first element: 3 first element: 4 first element: 4 first element: 1 first element: 2 first element: 3 first element: 4 first element: 4 first element: 3 first element: 4 first element: 4 first element: 2 first element: 3 first element: 4 first element: 4 first element: 3 ... and so on.
I'm expecting: first element: 0 first element: 1 first element: 2 first element: 3 first element: 4 (This is the output I am getting with Digital Pascal.)
Thanks for your help with this.
On 22 Jun 2004 at 16:45, Mingeborg@aol.com wrote:
I am getting a recursion problem I don't understand. (gpc-20040516, LINUX on a Pentium 4 laptop.)
This is a (silly) example program (enclosed as a gzipped tar file.):
program subset_problem(input,output); const setlimit = 4; type subset = set of 0..255;
var seta, setb: subset;
function recursive_setprint(set1: subset):subset;
[...]
I'm expecting: first element: 0 first element: 1 first element: 2 first element: 3 first element: 4 (This is the output I am getting with Digital Pascal.)
The output is the same with Virtual Pascal, Delphi, and FreePascal - so something is up with the GPC output.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Mingeborg@aol.com wrote:
I am getting a recursion problem I don't understand. (gpc-20040516, LINUX on a Pentium 4 laptop.)
This is a (silly) example program (enclosed as a gzipped tar file.):
I'm getting the following output: first element: 0 first element: 1 first element: 2 first element: 3 first element: 4 first element: 4 [...]
Thanks for the report. The attached patch will fix it. (inga1*.pas)
Frank
Frank Heckenbach wrote:
Mingeborg@aol.com wrote:
I am getting a recursion problem I don't understand. (gpc-20040516, LINUX on a Pentium 4 laptop.)
This is a (silly) example program (enclosed as a gzipped tar file.):
I'm getting the following output: first element: 0 first element: 1 first element: 2 first element: 3 first element: 4 first element: 4 [...]
Thanks for the report. The attached patch will fix it. (inga1*.pas)
This seems like a serious failure. I am surprised it wasn't caught by your test suite. Both that and the current beta should be revised IMO. What versions had it? What other conditions triggered it (maybe all nested function calls)?
CBFalconer wrote:
Frank Heckenbach wrote:
Mingeborg@aol.com wrote:
I am getting a recursion problem I don't understand. (gpc-20040516, LINUX on a Pentium 4 laptop.)
This is a (silly) example program (enclosed as a gzipped tar file.):
I'm getting the following output: first element: 0 first element: 1 first element: 2 first element: 3 first element: 4 first element: 4 [...]
Thanks for the report. The attached patch will fix it. (inga1*.pas)
This seems like a serious failure. I am surprised it wasn't caught by your test suite. Both that and the current beta should be revised IMO.
The test suite has been revised by adding Inga's test program to it. That's what I mean when I write `(inga1*.pas)'.
What versions had it? What other conditions triggered it (maybe all nested function calls)?
No -- that would be really serious.
In fact it affects on functions returning sets (so ISO 7185 code is not affected at all which should be good news for you :-), and only if range-checking is on (which it is by default), and thus only recently since the first bits of range-checking have been added. That's also probably why it wasn't caught earlier. Therefore, BTW, turning off range-checking would be a work-around.
Frank