-3

所以我的问题看起来像,我有两个程序,它们互相调用,但这会提供溢出。如何跳转到程序 - 像 asm jmp 不调用?我不想使用标签,因为我不能在两个不同的过程之间使用 GoTo。而且我不希望执行调用过程之后的代码。顺便说一句,我使用 FPC。

unit sample;
interface

procedure procone;
procedure proctwo;

implementation

procedure procone;
begin
writeln('Something');
proctwo;
writeln('After proctwo'); //don't execute this!
end;

procedure proctwo;
begin
writeln('Something else');
procone;
writeln('After one still in two'); //don't execute this either
end;

end.
4

1 回答 1

1

您必须使用函数参数来指示递归,以便函数知道它正在被相关函数调用。例如:

unit sample;

interface

procedure procone;
procedure proctwo;

implementation

procedure procone(const infunction : boolean);
begin
  writeln('Something');
  if infunction then exit;
  proctwo(true);
  writeln('After proctwo'); //don't execute this!
end;

procedure proctwo(const infunction : boolean);
begin
  writeln('Something else');
  if infunction then exit;
  procone(true);
  writeln('After one still in two'); //don't execute this either
end;

procedure usagesample;
begin
  writeln('usage sample');
  writeln;
  writeln('running procone');
  procone(false);
  writeln;
  writeln('running proctwo');
  proctwo(false);
end;

end.

usagesample被调用时,它应该产生这个:

usage sample

running procone
Something
Something else
After proctwo

running proctwo
Something else
Something
After one still in two
于 2012-07-18T01:38:19.450 回答