[net.wanted.sources] Bug in Pascal PI/PC

alexis@reed.UUCP (Dimitriadis) (11/16/84)

  I have run into a bug in Berkeley PI and PC.  I am not sure
what generation PI we have. Running `what' gives (among other 
things): main.c 1.9 6/10/83

  We are running ULTRIX, (close to 4.2 UNI*), on a VAX 11/780.
The bug was NOT there when we had Version 7 on a PDP 11/70.
I do not know whether the problem is peculiar to our PI/PC,
or to the VAX, or to the combination of the two.  (The PDP
did initialize registers to zero, whereas the VAX does not.
Some utilities broke as a result).

  Say you have a function with a for loop in it, and there
is a function call from inside the for loop. If the loop control
variable is an argument to the calling (enclosing) function,
(non-standard, but acceptable in UCB-Pascal),
both PC and PI get confused about the number of variables that
the called function should have. (See examples below).

    They will accept types that correspond to an initial subset of
the function's actual types. Thus it appears that they simply
look up the NUMBER of variables in the wrong place.

  The problem can be gotten around by using a local control 
variable, but it's a pain, especially if you don't know about it
beforehand. 

  So, if you have or can figure out a patch for it, could you
please mail us a diff, or at least let me know it's been posted?

	      "Thanks in Advance,"

	       Alexis Dimitriadis
		 alexis @ reed

---------------------------------------- cut disk here -----
program map(output);

(* This program produces a compiler diagnostic 
 * because a function argument (arg)
 * is used in the for loop enclosing the recursive call.
 * if a global or local variable is used to control the
 * loop, the bug disappears  *)

var
    glob, b:integer;

procedure tryout(arg,y: integer);
var 
    loc: integer;
begin
    (* A call from inside a for loop with an argument for
     * a control variable will run into the snag  *)
    for arg := 1 to 10 do
	tryout(arg,y);

    (* But a call with a local control variable will not *)
    for loc:= 1 to 10 do
	tryout(loc,y);

    (* Neither will one with an external (more global) control
     * variable  *)
    for glob := 1 to 10 do
	tryout(glob,y);

    (* If an argument is used as the control variable,
     * The compiler thinks that tryout needs ONE argument *)
    for arg := 1 to 10 do
	tryout(arg);

end;

begin
    tryout(glob,b);
end.