所以我的问题看起来像,我有两个程序,他们互相调用,但这可以提供溢出。如何JUMP到程序 - 像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.
答案 0 :(得分:1)
您必须使用函数参数来指示递归,以便函数知道它正被相关函数调用。 e.g:
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